From 27e96b151c73336700fc42e2310da4082aed6840 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 18 May 2014 00:30:22 +0200 Subject: Fix memory leak on termination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-server/mds-server.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c index c354134..1a553df 100644 --- a/src/mds-server/mds-server.c +++ b/src/mds-server/mds-server.c @@ -153,7 +153,7 @@ int main(int argc_, char** argv_) int unparsed_args_ptr = 1; char* unparsed_args[ARGC_LIMIT + LIBEXEC_ARGC_EXTRA_LIMIT + 1]; int i; - pthread_t _slave_thread; + pthread_t slave_thread; #if (LIBEXEC_ARGC_EXTRA_LIMIT < 3) # error LIBEXEC_ARGC_EXTRA_LIMIT is too small, need at least 3. @@ -400,12 +400,15 @@ int main(int argc_, char** argv_) with_mutex(slave_mutex, running_slaves++;); /* Start slave thread. */ - errno = pthread_create(&_slave_thread, NULL, slave_loop, (void*)(intptr_t)client_fd); + errno = pthread_create(&slave_thread, NULL, slave_loop, (void*)(intptr_t)client_fd); if (errno) { perror(*argv); with_mutex(slave_mutex, running_slaves--;); } + errno = pthread_detach(slave_thread); + if (errno) + perror(*argv); } terminate: @@ -700,6 +703,10 @@ void* slave_loop(void* data) msgbuf = NULL; + terminate: + if (reexecing) + goto reexec; + fail: /* The loop does break, this done on success as well. */ /* Close socket and free resources. */ close(socket_fd); @@ -718,7 +725,7 @@ void* slave_loop(void* data) return NULL; - terminate: + reexec: /* Tell the master thread that the slave has closed, this is done because re-exec causes a race-condition between the acception of a slave and the execution @@ -1712,7 +1719,7 @@ int unmarshal_server(int fd) size_t list_elements; size_t i; ssize_t node; - pthread_t _slave_thread; + pthread_t slave_thread; /* Read the file. */ @@ -1833,12 +1840,15 @@ int unmarshal_server(int fd) with_mutex(slave_mutex, running_slaves++;); /* Start slave thread. */ - errno = pthread_create(&_slave_thread, NULL, slave_loop, (void*)(intptr_t)socket_fd); + errno = pthread_create(&slave_thread, NULL, slave_loop, (void*)(intptr_t)socket_fd); if (errno) { perror(*argv); with_mutex(slave_mutex, running_slaves--;); } + errno = pthread_detach(slave_thread); + if (errno) + perror(*argv); } } -- cgit v1.2.3-70-g09d2