From: Florian Forster Date: Wed, 17 Jun 2015 08:26:21 +0000 (+0200) Subject: network plugin: Make sure all memory is freed when the receive thread fails. X-Git-Tag: collectd-5.5.1~105^2~6 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7f6c4a16fdacab6c11f8a7756f0d8438ce198288;p=collectd.git network plugin: Make sure all memory is freed when the receive thread fails. Not all that useful (your receive thread just died …) but hopefully makes the static analysis happy. --- diff --git a/src/network.c b/src/network.c index c5fd256f..04dffe8b 100644 --- a/src/network.c +++ b/src/network.c @@ -2421,7 +2421,7 @@ static int network_receive (void) /* {{{ */ receive_list_entry_t *private_list_tail; uint64_t private_list_length; - assert (listen_sockets_num > 0); + assert (listen_sockets_num > 0); private_list_head = NULL; private_list_tail = NULL; @@ -2430,15 +2430,14 @@ static int network_receive (void) /* {{{ */ while (listen_loop == 0) { status = poll (listen_sockets_pollfd, listen_sockets_num, -1); - if (status <= 0) { char errbuf[1024]; if (errno == EINTR) continue; - ERROR ("poll failed: %s", + ERROR ("network plugin: poll(2) failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); - return (-1); + break; } for (i = 0; (i < listen_sockets_num) && (status > 0); i++) @@ -2456,10 +2455,10 @@ static int network_receive (void) /* {{{ */ if (buffer_len < 0) { char errbuf[1024]; - ERROR ("recv failed: %s", - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); + status = (errno != 0) ? errno : -1; + ERROR ("network plugin: recv(2) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + break; } stats_octets_rx += ((uint64_t) buffer_len); @@ -2473,7 +2472,8 @@ static int network_receive (void) /* {{{ */ if (ent == NULL) { ERROR ("network plugin: malloc failed."); - return (-1); + status = ENOMEM; + break; } memset (ent, 0, sizeof (receive_list_entry_t)); ent->data = malloc (network_config_packet_size); @@ -2481,7 +2481,8 @@ static int network_receive (void) /* {{{ */ { sfree (ent); ERROR ("network plugin: malloc failed."); - return (-1); + status = ENOMEM; + break; } ent->fd = listen_sockets_pollfd[i].fd; ent->next = NULL; @@ -2517,7 +2518,12 @@ static int network_receive (void) /* {{{ */ private_list_tail = NULL; private_list_length = 0; } + + status = 0; } /* for (listen_sockets_pollfd) */ + + if (status != 0) + break; } /* while (listen_loop == 0) */ /* Make sure everything is dispatched before exiting. */ @@ -2540,7 +2546,7 @@ static int network_receive (void) /* {{{ */ pthread_mutex_unlock (&receive_list_lock); } - return (0); + return (status); } /* }}} int network_receive */ static void *receive_thread (void __attribute__((unused)) *arg)