On Sun, Mar 15, 2009 at 11:50 AM, DanKegel <daniel.r.ke...@gmail.com> wrote:
> Hi folks!
>
> 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();
> }
>
> This shows two leaks right now, but should show none, right?

As Nelson noted, you also need a PR_Cleanup() call after the
NSS_Shutdown() call.  Another call you need to make after
NSS_Shutdown() is PL_ArenaFinish(), which eliminates the
need to set the NSS_DISABLE_ARENA_FREE_LIST environment
variable to 1.  So the shutdown sequence should be:

  NSS_Shutdown();
  PL_ArenaFinish();
  PR_Cleanup();

Note: neither of the leaks you reported below is allocated by
NSPR, so it seems that you already filtered out memories
allocated by NSPR initialization.

> The first leak was mentioned by wtc in
> http://sources.redhat.com/bugzilla/show_bug.cgi?id=2451
> and shows up for me like this:
>
> 4 bytes in 1 blocks are definitely lost in loss record 1 of 6
>   at malloc (vg_replace_malloc.c:207)
>   by _dl_map_object_from_fd (in /lib32/ld-2.8.90.so)
> ...
>   by dlopen@@GLIBC_2.1 (in /lib32/libdl-2.8.90.so)
>   by pr_LoadLibraryByPathname (prlink.c:984)
>   by PR_LoadLibraryWithFlags (prlink.c:580)
>   by ???
>   by ???
> ...
>   by secmod_ModuleInit (pk11load.c:147)
>   by SECMOD_LoadPKCS11Module (pk11load.c:379)
>   by SECMOD_LoadModule (pk11pars.c:323)
>   by SECMOD_LoadModule (pk11pars.c:338)
>   by nss_Init (nssinit.c:541)
>
> (Side question: how did Wan-Teh get that nice backtrace?

I believe I got that backtrace from Sun's NSS test engineer :-)

In any case, that leak is most likely a libc bug.

> The second leak is:
>
> 72 bytes in 1 blocks are definitely lost in loss record 4 of 6
>   at calloc (vg_replace_malloc.c:397)
>   by PR_Calloc (prmem.c:474)
>   by error_get_my_stack (error.c:141)
>   by nss_ClearErrorStack (error.c:277)
>   by NSSArena_Create (arena.c:385)
>   by NSSTrustDomain_Create (trustdomain.c:74)
>   by STAN_LoadDefaultNSS3TrustDomain (pki3hack.c:141)
>   by nss_Init (nssinit.c:553)
>   by NSS_NoDB_Init (nssinit.c:700)
>   by main (foo.c:7)
>
> This is odd, as STAN_Shutdown pretty clearly tries to free the default
> trust domain.

This leak has been fixed in NSS 3.12.1:
https://bugzilla.mozilla.org/show_bug.cgi?id=431805

Are you still using NSS 3.12?  You can check the NSS version
with this command:
  ident libnss3.so | grep NSS

By the way, two weeks ago I wrote to Alexander Sack
(who maintains Ubuntu's NSS package) to ask him to
update the NSS package in Ubuntu 8.04 LTS to NSS
3.12.2 (the latest NSS 3.12.x release).

Wan-Teh
-- 
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto

Reply via email to