Nelson B Bolyard wrote:
DanKegel wrote, On 2009-03-15 11:50:
I'm looking at memory leaks, starting with the simple test program
#include <ssl.h>
#include <stdio.h>
int main()
{
NSS_NoDB_Init();
NSS_Shutdown();
For leak testing, there's one more important call to be placed here.
PR_Cleanup();
i call this function after NSS_Shutdown(), then whole program
hang at the call, and not quit for a long time, finally, i ctrl-c
}
NSPR in implicitly initialized but must be explicitly shutdown to
ensure no leaks.
Also, when doing leak testing, you will not get accurate leak stacks
from the various leak tools unless your test programs run with the
environment variable
NSS_DISABLE_ARENA_FREE_LIST=1
This is because NSS and NSPR have an allocator that recycles allocated
memory on a free list. These get allocated and freed many times in NSS
but most of those times, the "free" actually just puts it on a free list
rather than actually freeing back to the heap. Consequently, if such a
block actually is leaked by some block of code that got it from the free
list, the allocation stack captured by malloc will be for the first block
of code that allocated it from the heap, (which may well have not leaked
it), rather than showing the block of code that actually allocated the
leaked block from the free list and then leaked it. So, to get accurate
leak stacks, it is necessary to disable this free list, causing all frees to
actually free back to the heap.
NSS clears the free list during shutdown, so the free list won't create
any new leaks, but it does cause the reported leak stacks to be wrong.
This shows two leaks right now, but should show none, right?
What versions of NSS and NSPR are you using? Also, if you're using a
version that is part of a Linux distro, which Linux distro does it
come from?
Sadly, some of the Linux distros really change NSS, so we can only accept
reports about leaks if they are found using Mozilla's NSS, or an NSS built
from Mozilla's sources.
i also have some leaks in using NSS, which is from F10(updates)
(nss-3.12.2.0-4.fc10.i386)
i use valgrind to get following memory leak reports, after
NSS_ShutDown() called:
==21093== 6 bytes in 1 blocks are still reachable in loss record 1 of 6
==21093== at 0x4006AEE: malloc (vg_replace_malloc.c:207)
==21093== by 0x3D7C959: (within /lib/libnspr4.so)
==21093== by 0x3D830D4: (within /lib/libnspr4.so)
==21093== by 0x3D8C9A4: PR_NewLock (in /lib/libnspr4.so)
==21093== by 0x7F0048C: (within /lib/libnss3.so)
==21093== by 0x7EBD7EB: (within /lib/libnss3.so)
==21093== by 0x7EBE051: NSS_NoDB_Init (in /lib/libnss3.so)
==21093== 55 bytes in 11 blocks are still reachable in loss record 3 of 6
==21093== at 0x4006AEE: malloc (vg_replace_malloc.c:207)
==21093== by 0x51D0EF: strdup (in /lib/libc-2.9.so)
==21093== by 0x3D77A46: PR_NewLogModule (in /lib/libnspr4.so)
==21093== by 0x3D82F71: (within /lib/libnspr4.so)
==21093== by 0x3D8C9A4: PR_NewLock (in /lib/libnspr4.so)
==21093== by 0x7F0048C: (within /lib/libnss3.so)
==21093== by 0x7EBD7EB: (within /lib/libnss3.so)
==21093== by 0x7EBE051: NSS_NoDB_Init (in /lib/libnss3.so)
==21093== 4,024 bytes in 54 blocks are still reachable in loss record 5 of 6
==21093== at 0x4004BA2: calloc (vg_replace_malloc.c:397)
==21093== by 0x3D7D039: PR_Calloc (in /lib/libnspr4.so)
==21093== by 0x3D77A38: PR_NewLogModule (in /lib/libnspr4.so)
==21093== by 0x3D82F71: (within /lib/libnspr4.so)
==21093== by 0x3D8C9A4: PR_NewLock (in /lib/libnspr4.so)
==21093== by 0x7F0048C: (within /lib/libnss3.so)
==21093== by 0x7EBD7EB: (within /lib/libnss3.so)
==21093== by 0x7EBE051: NSS_NoDB_Init (in /lib/libnss3.so)
==21093== 5,563 bytes in 16 blocks are still reachable in loss record 6 of 6
==21093== at 0x4006AEE: malloc (vg_replace_malloc.c:207)
==21093== by 0x3D7CDC7: PR_Malloc (in /lib/libnspr4.so)
==21093== by 0x3D8C0B2: PR_NewCondVar (in /lib/libnspr4.so)
==21093== by 0x3D92E3D: (within /lib/libnspr4.so)
==21093== by 0x3D830A6: (within /lib/libnspr4.so)
==21093== by 0x3D8C9A4: PR_NewLock (in /lib/libnspr4.so)
==21093== by 0x7F0048C: (within /lib/libnss3.so)
==21093== by 0x7EBD7EB: (within /lib/libnss3.so)
==21093== by 0x7EBE051: NSS_NoDB_Init (in /lib/libnss3.so)
==14612== 12 bytes in 1 blocks are definitely lost in loss record 2 of 7
==14612== at 0x4006AEE: malloc (vg_replace_malloc.c:207)
==14612== by 0x3D7CDC7: PR_Malloc (in /lib/libnspr4.so)
==14612== by 0x7E9E677: PORT_Alloc_Util (in /lib/libnssutil3.so)
==14612== by 0x7E9B21C: (within /lib/libnssutil3.so)
==14612== by 0x7E9C880: SEC_ASN1EncodeItem_Util (in /lib/libnssutil3.so)
==14612== by 0x450A2D8: ???
==14612== by 0x450A7E8: ???
==14612== by 0x450B547: ???
==14612== by 0x44EE28F: ???
==14612== by 0x7ED68A8: PK11_InitPin (in /lib/libnss3.so)
==14612== by 0x8049868: main (rsakey_gen.c:61)
==14612== 19 bytes in 1 blocks are still reachable in loss record 3 of 7
==14612== at 0x4006AEE: malloc (vg_replace_malloc.c:207)
==14612== by 0x51D0EF: strdup (in /lib/libc-2.9.so)
==14612== by 0x3D7C575: PR_LoadLibraryWithFlags (in /lib/libnspr4.so)
==14612== by 0x450FCCA: ???
==14612== by 0x450FD24: ???
==14612== by 0x450FEEF: ???
==14612== by 0x3D83342: PR_CallOnce (in /lib/libnspr4.so)
==14612== by 0x450DFE9: ???
==14612== by 0x44F04AC: ???
==14612== by 0x44F0752: ???
==14612== by 0x7EDD572: (within /lib/libnss3.so)
==14612== by 0x7EDDB97: (within /lib/libnss3.so)
==14612== 20 bytes in 1 blocks are still reachable in loss record 4 of 7
==14612== at 0x4004BA2: calloc (vg_replace_malloc.c:397)
==14612== by 0x6480C5: _dlerror_run (in /lib/libdl-2.9.so)
==14612== by 0x647B60: dlopen@@GLIBC_2.1 (in /lib/libdl-2.9.so)
==14612== by 0x3D7D247: (within /lib/libnspr4.so)
==14612== by 0x3D82F5E: (within /lib/libnspr4.so)
==14612== by 0x3D8C9A4: PR_NewLock (in /lib/libnspr4.so)
==14612== by 0x7F0048C: (within /lib/libnss3.so)
==14612== by 0x7EBD7EB: (within /lib/libnss3.so)
==14612== by 0x7EBE258: NSS_InitReadWrite (in /lib/libnss3.so)
==14612== by 0x80497A6: main (rsakey_gen.c:49)
==14612== 888 bytes in 7 blocks are still reachable in loss record 6 of 7
==14612== at 0x4004BA2: calloc (vg_replace_malloc.c:397)
==14612== by 0x3D7D039: PR_Calloc (in /lib/libnspr4.so)
==14612== by 0x3D7BB45: (within /lib/libnspr4.so)
==14612== by 0x3D83064: (within /lib/libnspr4.so)
==14612== by 0x3D8C9A4: PR_NewLock (in /lib/libnspr4.so)
==14612== by 0x7F0048C: (within /lib/libnss3.so)
==14612== by 0x7EBD7EB: (within /lib/libnss3.so)
==14612== by 0x7EBE258: NSS_InitReadWrite (in /lib/libnss3.so)
==14612== by 0x80497A6: main (rsakey_gen.c:49)
==14612== 18,359 bytes in 14 blocks are still reachable in loss record 7
of 7
==14612== at 0x4006AEE: malloc (vg_replace_malloc.c:207)
==14612== by 0x3D7CDC7: PR_Malloc (in /lib/libnspr4.so)
==14612== by 0x3D82558: PR_ErrorInstallTable (in /lib/libnspr4.so)
==14612== by 0x3D8229F: (within /lib/libnspr4.so)
==14612== by 0x3D8310C: (within /lib/libnspr4.so)
==14612== by 0x3D8C9A4: PR_NewLock (in /lib/libnspr4.so)
==14612== by 0x7F0048C: (within /lib/libnss3.so)
==14612== by 0x7EBD7EB: (within /lib/libnss3.so)
==14612== by 0x7EBE258: NSS_InitReadWrite (in /lib/libnss3.so)
==14612== by 0x80497A6: main (rsakey_gen.c:49)
above reports come from two program, as the pid indicationg.
In my system, it seems that the environment var not set:
$ echo ${NSS_DISABLE_ARENA_FREE_LIST}
$
result is blank
[snip...]
--
dev-tech-crypto mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-crypto