net: Fix coap_new_endpoint error handling

The wrong sequence caused segfaults instead of regular error returns
using LWIP (where the error is visible eg. when binding to a different
address type than the socket was created for).

The free in the error path is fixed as well. (coap_malloc_type requires
a coap_free_type as per documentation, although some implementations
might not be strict about it).
This commit is contained in:
chrysn authored and Olaf Bergmann committed 2016-06-22 12:36:13 +02:00
1 parent 748b788e72
commit 0e7e269ecb
1 file changed
+4 -4
+4 -4
View File
@@ -380,12 +380,12 @@ coap_new_context(
prng((unsigned char *)&c->message_id, sizeof(unsigned short));
c->endpoint = coap_new_endpoint(listen_addr, COAP_ENDPOINT_NOSEC);
#ifdef WITH_LWIP
c->endpoint->context = c;
#endif
if (c->endpoint == NULL) {
goto onerror;
}
#ifdef WITH_LWIP
c->endpoint->context = c;
#endif
#ifdef WITH_POSIX
c->sockfd = c->endpoint->handle.fd;
@@ -411,7 +411,7 @@ coap_new_context(
return c;
onerror:
coap_free(c);
coap_free_type(COAP_CONTEXT, c);
return NULL;
}