[Pixman] pixman 0.18.2 leaking memory in threaded invocations by cairo on Mac OS X 10.5.8

Dr. Rolf Jansen rj at cyclaero.com
Wed Jun 30 11:02:50 PDT 2010


Hi Soren,

I downloaded pixman-0.19.1 with your patch applied from your site, and  
that resolved the issue on Mac OS X.

Many thanks for your kind efforts.


Regarding Windows, I am far away from offering a solution. However,  
until somebody comes-up with the real fix, perhaps it would be of some  
help, if a programmer using pixman would have a chance to explicitly  
free the TLS. For example, I wouldn't have mind to call something like  
freePixmanTLS() at the exit points of my threads. This is not that  
nice, but perhaps it helps for the time being.

Best regards

Rolf


Am 30.06.2010 um 04:04 schrieb Soeren Sandmann:

> Hi,
>
>> The problem is now that the daemon is leaking 256 bytes of memory on
>> every PNG production. I analysed the problem with an OS X tool called
>> MallocDebug, and it turned out that the leaked memory was allocated  
>> in
>> pixman. If cairo/pixman is invoked from the main thread only, then I
>> observe no leaking. Also a first time invocation from any thread does
>> not result in leaking. If cairo/pixman is invoked from a spawned
>> thread, then the leak occurs, once the thread is finished.
>
> Thanks for reporting the bug.
>
>> I read something about pixman utilizing TLS (thread local strorage),
>> and I suspected that the observed leaking may be somehow related, but
>> my config.log tells us:
>>
>> conftest.c:31: error: thread-local storage not supported for this
>> target
>
> That error message is somewhat misleading. It is a GCC error that _it_
> doesn't support the use of __thread on Mac OS X.
>
> Pixman instead uses pthreads for thread local storage on Mac OS X, and
> the problem you are seeing is related to that. Basically we need to
> free the stored data when a thread exists.
>
> The patch included is an attempt at fixing this. If you can test it,
> that would be appreciated. There is a tarball here:
>
>        http://www.daimi.au.dk/~sandmann/pixman-0.19.1.tar.gz
>
> which has the patch included.
>
> It seems we have the same problem on Windows. Unfortunately, I don't
> really have any idea how to fix it there. If anyone can help out, that
> would be appreciated.
>
>
> Thanks,
> Soren
>
>
>
> From 2e22e3435e1c1171c7ae840b4bf017b16e1fe52a Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?S=C3=B8ren=20Sandmann=20Pedersen?= <ssp at redhat.com>
> Date: Wed, 30 Jun 2010 02:31:10 -0400
> Subject: [PATCH] Fix memory leak in the pthreads thread local  
> storage code
>
> 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