[PATCH] Fix memory leak in the pthreads thread local storage code
Søren Sandmann Pedersen
ssp at redhat.com
Tue Jun 29 23:31:10 PDT 2010
When a thread exits, we leak whatever is stored in thread local
variables, so install a destructor to free it.
---
pixman/pixman-compiler.h | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/pixman/pixman-compiler.h b/pixman/pixman-compiler.h
index f0f9d91..2b15cc3 100644
--- a/pixman/pixman-compiler.h
+++ b/pixman/pixman-compiler.h
@@ -72,9 +72,9 @@
/* TLS */
#if defined(PIXMAN_NO_TLS)
-# define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \
+# define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \
static type name
-# define PIXMAN_GET_THREAD_LOCAL(name) \
+# define PIXMAN_GET_THREAD_LOCAL(name) \
(&name)
#elif defined(TOOLCHAIN_SUPPORTS__THREAD)
@@ -165,9 +165,16 @@ extern __stdcall int ReleaseMutex (void *);
static pthread_key_t tls_ ## name ## _key; \
\
static void \
+ tls_ ## name ## _destroy_value (void *value) \
+ { \
+ free (value); \
+ } \
+ \
+ static void \
tls_ ## name ## _make_key (void) \
{ \
- pthread_key_create (&tls_ ## name ## _key, NULL); \
+ pthread_key_create (&tls_ ## name ## _key, \
+ tls_ ## name ## _destroy_value); \
} \
\
static type * \
--
1.7.0.1
More information about the Pixman
mailing list