Hi,

While going through fixing memory leaks in CHASM[1], I fixed some leaks
within NSPR and NSS. Here's a list of the leaks that CHASM exposed
(doing minimal things with NSS, basically just hashing):

  * The error tables are not cleaned up. This is the most invasive
    change since it adds a new public function
    (nspr_CleanupPRErrorTables) which cleans up *all* error tables. This
    means that anything that calls this cleans up every error table that
    has been installed. Unfortunately, I see no better way of handling
    this since everything is already not threadsafe. This is then called
    in PR_Cleanup (The positioning may be too early, but I put it in
    reverse order that PR_InitStuff does). A note was also added to the
    PR_Cleanup comment.
  * Clean up the TPD pointer within _PR_CleanupTPD.
  * Call PL_ArenaFinish when cleaning up the arenas.

These patches have made CHASM run silently (as far as NSS/NSPR are
concerned, glibc has a leak in it yet) under valgrind.

I ran the tests, but many failed due to my machine not having a fully
qualified domain name. Since these changes affect cleanup, they
*probably* don't affect other things, but I can set up a machine with a
proper fqdn and rerun the tests (with and without my patches). Thanks.

--Ben

[1]http://chasmd.org
Index: nsprpub/pr/include/prerr.h
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/include/prerr.h,v
retrieving revision 3.10
diff -u -r3.10 prerr.h
--- nsprpub/pr/include/prerr.h  10 May 2007 01:21:41 -0000      3.10
+++ nsprpub/pr/include/prerr.h  7 Apr 2010 20:03:17 -0000
@@ -276,6 +276,7 @@
 #define PR_MAX_ERROR                             (-5924L)
 
 extern void nspr_InitializePRErrorTable(void);
+extern void nspr_CleanupPRErrorTables(void);
 #define ERROR_TABLE_BASE_nspr (-6000L)
 
 #endif /* prerr_h___ */
Index: nsprpub/pr/include/prerror.h
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/include/prerror.h,v
retrieving revision 3.14
diff -u -r3.14 prerror.h
--- nsprpub/pr/include/prerror.h        28 May 2007 14:48:26 -0000      3.14
+++ nsprpub/pr/include/prerror.h        7 Apr 2010 20:03:17 -0000
@@ -304,6 +304,17 @@
 
 
 /***********************************************************************
+** FUNCTION:    PR_ErrorCleanupTables
+** DESCRIPTION:
+**  Unregisters all error tables with NSPR.
+**
+**  NOT THREAD SAFE!
+**  
+***********************************************************************/
+NSPR_API(void) PR_ErrorCleanupTables();
+
+
+/***********************************************************************
 ** FUNCTION:    PR_ErrorInstallCallback
 ** DESCRIPTION:
 **  Registers an error localization plugin with NSPR.  May be called
Index: nsprpub/pr/src/linking/prlink.c
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/src/linking/prlink.c,v
retrieving revision 3.108
diff -u -r3.108 prlink.c
--- nsprpub/pr/src/linking/prlink.c     30 Mar 2010 19:01:52 -0000      3.108
+++ nsprpub/pr/src/linking/prlink.c     7 Apr 2010 20:03:18 -0000
@@ -249,8 +249,6 @@
  */
 void _PR_ShutdownLinker(void)
 {
-    /* FIXME: pr_exe_loadmap should be destroyed. */
-    
     PR_DestroyMonitor(pr_linker_lock);
     pr_linker_lock = NULL;
 
@@ -258,6 +256,9 @@
         free(_pr_currentLibPath);
         _pr_currentLibPath = NULL;
     }
+
+    PR_FREEIF(pr_exe_loadmap->name);
+    PR_FREEIF(pr_exe_loadmap);
 }
 
 
/******************************************************************************/
Index: nsprpub/pr/src/misc/prerr.c
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/src/misc/prerr.c,v
retrieving revision 3.11
diff -u -r3.11 prerr.c
--- nsprpub/pr/src/misc/prerr.c 10 May 2007 01:21:41 -0000      3.11
+++ nsprpub/pr/src/misc/prerr.c 7 Apr 2010 20:03:18 -0000
@@ -127,3 +127,7 @@
 void nspr_InitializePRErrorTable(void) {
     PR_ErrorInstallTable(&et);
 }
+
+void nspr_CleanupPRErrorTables(void) {
+    PR_ErrorCleanupTables();
+}
Index: nsprpub/pr/src/misc/prerrortable.c
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/src/misc/prerrortable.c,v
retrieving revision 3.8
diff -u -r3.8 prerrortable.c
--- nsprpub/pr/src/misc/prerrortable.c  25 Apr 2004 15:01:01 -0000      3.8
+++ nsprpub/pr/src/misc/prerrortable.c  7 Apr 2010 20:03:18 -0000
@@ -217,6 +217,26 @@
 }
 
 PR_IMPLEMENT(void)
+PR_ErrorCleanupTables()
+{
+    struct PRErrorTableList *et;
+
+    et = Table_List;
+
+    while (et) {
+        struct PRErrorTableList *cet;
+
+        cet = et->next;
+
+        PR_FREEIF(et);
+
+        et = cet;
+    }
+
+    Table_List = NULL;
+}
+
+PR_IMPLEMENT(void)
 PR_ErrorInstallCallback(const char * const * languages,
                       PRErrorCallbackLookupFn *lookup, 
                       PRErrorCallbackNewTableFn *newtable,
Index: nsprpub/pr/src/misc/prinit.c
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/src/misc/prinit.c,v
retrieving revision 3.54
diff -u -r3.54 prinit.c
--- nsprpub/pr/src/misc/prinit.c        3 Apr 2010 18:16:24 -0000       3.54
+++ nsprpub/pr/src/misc/prinit.c        7 Apr 2010 20:03:18 -0000
@@ -365,6 +365,9 @@
  *   PR_Cleanup() only responds when it is called by the primordial
  *   thread. Calls by any other thread are silently ignored.
  *
+ *   PR_Cleanup() calls nspr_CleanupPRErrorTables() which invalidates
+ *   all error tables that have been installed.
+ *
  * See also: PR_ExitProcess()
  *
  *----------------------------------------------------------------------
@@ -411,6 +414,8 @@
 
         _PR_MD_EARLY_CLEANUP();
 
+        nspr_CleanupPRErrorTables();
+
         _PR_CleanupMW();
         _PR_CleanupTime();
         _PR_CleanupDtoa();
Index: nsprpub/pr/src/pthreads/ptthread.c
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/src/pthreads/ptthread.c,v
retrieving revision 3.86
diff -u -r3.86 ptthread.c
--- nsprpub/pr/src/pthreads/ptthread.c  3 Apr 2010 18:16:25 -0000       3.86
+++ nsprpub/pr/src/pthreads/ptthread.c  7 Apr 2010 20:03:18 -0000
@@ -1048,6 +1048,8 @@
 
         _PR_MD_EARLY_CLEANUP();
 
+        nspr_CleanupPRErrorTables();
+
         _PR_CleanupMW();
         _PR_CleanupTime();
         _PR_CleanupDtoa();
@@ -1080,6 +1082,7 @@
 #ifdef _PR_ZONE_ALLOCATOR
         _PR_DestroyZones();
 #endif
+        _PR_CleanupTPD();
         _pr_initialized = PR_FALSE;
         return PR_SUCCESS;
     }
Index: nsprpub/pr/src/threads/prtpd.c
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/src/threads/prtpd.c,v
retrieving revision 3.13
diff -u -r3.13 prtpd.c
--- nsprpub/pr/src/threads/prtpd.c      3 Apr 2010 18:16:25 -0000       3.13
+++ nsprpub/pr/src/threads/prtpd.c      7 Apr 2010 20:03:18 -0000
@@ -104,6 +104,7 @@
 */
 void _PR_CleanupTPD(void)
 {
+    PR_FREEIF(_pr_tpd_destructors);
 }  /* _PR_CleanupTPD */
 
 /*
Index: security/nss/lib/base/arena.c
===================================================================
RCS file: /cvsroot/mozilla/security/nss/lib/base/arena.c,v
retrieving revision 1.13
diff -u -r1.13 arena.c
--- security/nss/lib/base/arena.c       15 Mar 2010 08:29:31 -0000      1.13
+++ security/nss/lib/base/arena.c       7 Apr 2010 20:03:20 -0000
@@ -1154,5 +1154,6 @@
 #ifdef DEBUG
   rv = nssPointerTracker_finalize(&arena_pointer_tracker);
 #endif
+  PL_ArenaFinish();
   return rv;
 }

Attachment: pgpO1zUNiko1x.pgp
Description: PGP signature

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

Reply via email to