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 - 3.10
+++ nsprpub/pr/include/prerr.h 7 Apr 2010 20:03:17 -
@@ -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.h28 May 2007 14:48:26 - 3.14
+++ nsprpub/pr/include/prerror.h7 Apr 2010 20:03:17 -
@@ -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 - 3.108
+++ nsprpub/pr/src/linking/prlink.c 7 Apr 2010 20:03:18 -
@@ -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 - 3.11
+++ nsprpub/pr/src/misc/prerr.c 7 Apr 2010 20:03:18 -
@@ -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 - 3.8
+++ nsprpub/pr/src/misc/prerrortable.c 7 Apr 2010 20:03:18 -
@@ -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: