From 1340d134ef60ce33037e39a0ce368cf1c940a2d7 Mon Sep 17 00:00:00 2001 From: cperciva Date: Sun, 13 Jun 2010 01:13:36 +0000 Subject: In threaded processes, destroy the mutex atexit_mutex when we've finished using it. This allows the mutex's allocated memory to be freed. This is one sense a rather silly change, since at this point we're less than a microsecond away from calling _exit; but fixing this memory leak is likely to make life easier for anyone trying to track down other memory leaks. --- lib/libc/stdlib/atexit.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/libc') diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c index efd1264..aba3edd 100644 --- a/lib/libc/stdlib/atexit.c +++ b/lib/libc/stdlib/atexit.c @@ -54,6 +54,7 @@ static pthread_mutex_t atexit_mutex = PTHREAD_MUTEX_INITIALIZER; #define _MUTEX_LOCK(x) if (__isthreaded) _pthread_mutex_lock(x) #define _MUTEX_UNLOCK(x) if (__isthreaded) _pthread_mutex_unlock(x) +#define _MUTEX_DESTROY(x) if (__isthreaded) _pthread_mutex_destroy(x) struct atexit { struct atexit *next; /* next in list */ @@ -182,4 +183,6 @@ __cxa_finalize(void *dso) } } _MUTEX_UNLOCK(&atexit_mutex); + if (dso == NULL) + _MUTEX_DESTROY(&atexit_mutex); } -- cgit v1.1