[asterisk-dev] Thread-local storage in linked lib cause memory leak

Alex Massover alex at jajah.com
Sun Jul 18 06:15:08 CDT 2010


Hi,

I have a custom module that linked to external library. Inside that library there's following declaration:

#define HOSTBUF_SIZE 1024
static __thread char tmphostbuf[HOSTBUF_SIZE];

I.e. there's buffer stored in thread local storage.

When I link this library to my unit test program (also multi-threaded) everything is OK, and there's no memory leaks in unit test.

But when I link this library to my custom Asterisk module, there's memory leak. I can observe the memory leak and valgrind confirms that there's memory leak in the function that uses this buffer, and the leak is exactly 1024 bytes per call (thread), and there's no leak if I don't call the function that uses this buffer. So it's for sure that this buffer causes the leak. Somehow this buffer is neither freed no reused.

AFAIK buffer in TLS does not supposed to leak and it doesn't leak when the lib is linked to my unit test program. But it leaks when the lib is linked to asterisk module. This module does nothing special (no new threads inside, no locks etc.).


Does Asterisk do something tricky with threads and that can break TLS in linked lib?

It would be great if somebody could enlighten me on the subj. The issue might be relevant in general to the libs Asterisk is linked to, not only to my specific example.

--
Best Regards,
Alex Massover
VoIP R&D TL
Jajah Inc.


This mail was sent via Mail-SeCure System.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20100718/ab1d10ed/attachment.htm 


More information about the asterisk-dev mailing list