coap_io.c: Fix file descriptor leaks when "connections" fail

If a TCP connection connection fails, or a an ICMP Unreachable is received
for a UDP packet, then the file descriptor is not closed off.  Eventually
all fails when no more file descriptors are allowed.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2018-02-15 09:51:05 +00:00
1 parent 0d2922a45b
commit 47b46d6907
1 file changed
+5 -4
+5 -4
View File
@@ -315,7 +315,7 @@ coap_socket_connect_tcp1(coap_socket_t *sock,
return 1;
}
coap_log(LOG_WARNING, "coap_socket_connect_tcp1: connect: %s\n", coap_socket_strerror());
return 0;
goto error;
}
if (getsockname(sock->fd, &local_addr->addr.sa, &local_addr->size) == COAP_SOCKET_ERROR) {
@@ -850,9 +850,10 @@ coap_network_read(coap_socket_t *sock, coap_packet_t *packet) {
#else
if (errno == ECONNREFUSED) {
#endif
/* client-side ICMP destination unreachable, ignore it */
coap_log(LOG_WARNING, "coap_network_read: unreachable\n");
return -2;
/* client-side ICMP destination unreachable, ignore it */
coap_log(LOG_WARNING, "coap_network_read: unreachable\n");
coap_socket_close(sock);
return -2;
}
coap_log(LOG_WARNING, "coap_network_read: %s\n", coap_socket_strerror());
goto error;