On 18/08/07, Paul Klissner <[EMAIL PROTECTED]> wrote:
> We found that under stress testing the 'launcher ' (a new daemon used to
> fire up
> multiple instances) was leaking about 1Gb / day, when multiple threads were
> calling SCardEstablishContext()/SCardReleaseContext() in a fast loop.
>
> It took awhile to find the source of that leak.
>
> libumem analysis showed mmap() calls leaked, but didn't show who the mmap()
> caller was. DTrace was used to determine that the call that leaked it
> was pthread_attr_init().
>
> The bug is that SYS_ThreadCreate(), the PCSClite wrapper for the POSIX
> thread library,
> calls pthread_attr_init(), which allocates memory, without the calling
> the counterpart
> call, pthread_attr_destroy() to release the memory.
Solved in revision 2615 [1].
Thanks for the bug report.
> And the thread
> library calls mmap()
> instead of malloc() to grow memory (at least indirectly).
I don't think I can do anything with this problem. pcsc-lite does not
provide the thread library.
> Adding a pthread_attr_destroy() call right after pthread_create() fixes
> it (after some
> re-arrangement of the 'if' statement).
>
> INTERNAL *int* *SYS_ThreadCreate*(PCSCLITE_THREAD_T * pthThread, *int*
> attributes,
> PCSCLITE_THREAD_FUNCTION(pvFunction), LPVOID pvArg)
> {
> pthread_attr_t attr;
>
> *if* (0 != pthread_attr_init(&attr))
> *return* FALSE;
>
> *if* (0 != pthread_attr_setdetachstate(&attr,
> attributes & THREAD_ATTR_DETACHED ? PTHREAD_CREATE_DETACHED :
> PTHREAD_CREATE_JOINABLE))
> *return* FALSE;
>
> *if* (0 == pthread_create(pthThread, &attr, pvFunction, pvArg))
> *return* TRUE;
> *else*
> *return* FALSE;
It is always a good idea to propose a patch that works for you instead
of a cut and paste of the original code (use diff --unified to
generate the patch).
I hope my modification fixes the problem but I can't be sure. From my
manpage I have: "pthread_attr_destroy does nothing in the LinuxThreads
implementation.". So no memory is allocated or freed under Linux.
Bye,
[1]
http://lists.alioth.debian.org/pipermail/pcsclite-cvs-commit/2007-August/002782.html
--
Dr. Ludovic Rousseau
_______________________________________________
Muscle mailing list
[email protected]
http://lists.drizzle.com/mailman/listinfo/muscle