From: Gerrie Roos Date: Fri, 25 May 2012 03:38:47 +0000 (+0200) Subject: Fixed various collectd memory leaks. X-Git-Tag: collectd-5.0.5~4^2~17 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5abe911631a15dd312d83db92c9dd9da9f13c9df;p=collectd.git Fixed various collectd memory leaks. Once I understood what's going on I tried to keep the changes to a minimum. Signed-off-by: Florian Forster --- diff --git a/src/collectd.c b/src/collectd.c index b68aea5c..6b77d599 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -77,6 +77,7 @@ static void sig_usr1_handler (int __attribute__((unused)) signal) pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); pthread_create (&thread, &attr, do_flush, NULL); + pthread_attr_destroy (&attr); } static int init_hostname (void) diff --git a/src/exec.c b/src/exec.c index 34c88a1c..dd295e98 100644 --- a/src/exec.c +++ b/src/exec.c @@ -824,6 +824,7 @@ static int exec_read (void) /* {{{ */ pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); pthread_create (&t, &attr, exec_read_one, (void *) pl); + pthread_attr_destroy (&attr); } /* for (pl) */ return (0); @@ -867,6 +868,7 @@ static int exec_notification (const notification_t *n, /* {{{ */ pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); pthread_create (&t, &attr, exec_notification_one, (void *) pln); + pthread_attr_destroy (&attr); } /* for (pl) */ return (0); diff --git a/src/meta_data.c b/src/meta_data.c index b502b377..ea98ba94 100644 --- a/src/meta_data.c +++ b/src/meta_data.c @@ -250,6 +250,7 @@ void meta_data_destroy (meta_data_t *md) /* {{{ */ if (md == NULL) return; + pthread_mutex_destroy(&md->lock); md_entry_free (md->head); pthread_mutex_destroy (&md->lock); free (md); diff --git a/src/unixsock.c b/src/unixsock.c index 0b897482..34442471 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -187,6 +187,7 @@ static void *us_handle_client (void *arg) close (fdin); close (fdout); pthread_exit ((void *) 1); + return ((void *) 1); } fhout = fdopen (fdout, "w"); @@ -198,6 +199,7 @@ static void *us_handle_client (void *arg) fclose (fhin); /* this closes fdin as well */ close (fdout); pthread_exit ((void *) 1); + return ((void *) 1); } /* change output buffer to line buffered mode */ @@ -209,6 +211,7 @@ static void *us_handle_client (void *arg) fclose (fhin); fclose (fhout); pthread_exit ((void *) 1); + return ((void *) 0); } while (42) @@ -250,6 +253,7 @@ static void *us_handle_client (void *arg) fclose (fhin); fclose (fhout); pthread_exit ((void *) 1); + return ((void *) 1); } if (strcasecmp (fields[0], "getval") == 0) @@ -304,6 +308,9 @@ static void *us_server_thread (void __attribute__((unused)) *arg) pthread_t th; pthread_attr_t th_attr; + pthread_attr_init (&th_attr); + pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED); + if (us_open_socket () != 0) pthread_exit ((void *) 1); @@ -322,6 +329,7 @@ static void *us_server_thread (void __attribute__((unused)) *arg) sstrerror (errno, errbuf, sizeof (errbuf))); close (sock_fd); sock_fd = -1; + pthread_attr_destroy (&th_attr); pthread_exit ((void *) 1); } @@ -338,9 +346,6 @@ static void *us_server_thread (void __attribute__((unused)) *arg) DEBUG ("Spawning child to handle connection on fd #%i", *remote_fd); - pthread_attr_init (&th_attr); - pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED); - status = pthread_create (&th, &th_attr, us_handle_client, (void *) remote_fd); if (status != 0) { @@ -355,6 +360,7 @@ static void *us_server_thread (void __attribute__((unused)) *arg) close (sock_fd); sock_fd = -1; + pthread_attr_destroy (&th_attr); status = unlink ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH); if (status != 0) diff --git a/src/utils_fbhash.c b/src/utils_fbhash.c index d20b7e39..97f21a1f 100644 --- a/src/utils_fbhash.c +++ b/src/utils_fbhash.c @@ -234,6 +234,7 @@ void fbh_destroy (fbhash_t *h) /* {{{ */ if (h == NULL) return; + pthread_mutex_destroy (&h->lock); free (h->filename); fbh_free_tree (h->tree); } /* }}} void fbh_destroy */