Memory leak fixes

2010-04-07 Thread Ben Boeckel
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: 

Re: Memory leak fixes

2010-04-07 Thread Reed Loden
On Wed, 7 Apr 2010 16:18:41 -0400
Ben Boeckel maths...@gmail.com wrote:

 While going through fixing memory leaks in CHASM[1], I fixed some leaks
 within NSPR and NSS.

Ben, thanks for the work here. Always great to have outside
contributions for Mozilla projects. Open source is what makes this
project great.

If you wouldn't mind, would you please submit your patches directly via
Bugzilla[0] so they can be processed appropriately? You'll need to split
your patch into separate NSS and NSPR parts, as they are tracked
as separate products, but if you can get your patches filed in Bugzilla,
I'm sure the NSS and NSPR developers would love to review them.

https://developer.mozilla.org/en/Getting_your_patch_in_the_tree has
some good information on how to get your patch landed. Let us know if
you have any questions.

Thanks again for your contribution!

~reed

[0] https://bugzilla.mozilla.org/

-- 
Reed Loden - r...@reedloden.com

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


Re: Memory leak fixes

2010-04-07 Thread Ben Boeckel
In article 20100407160150.2b5d0637.r...@reedloden.com you wrote:
 On Wed, 7 Apr 2010 16:18:41 -0400
 Ben Boeckel maths...@gmail.com wrote:
 
 While going through fixing memory leaks in CHASM[1], I fixed some leaks
 within NSPR and NSS.
 
 Ben, thanks for the work here. Always great to have outside
 contributions for Mozilla projects. Open source is what makes this
 project great.
 
 If you wouldn't mind, would you please submit your patches directly via
 Bugzilla[0] so they can be processed appropriately? You'll need to split
 your patch into separate NSS and NSPR parts, as they are tracked
 as separate products, but if you can get your patches filed in Bugzilla,
 I'm sure the NSS and NSPR developers would love to review them.

Sure[1][2].

 https://developer.mozilla.org/en/Getting_your_patch_in_the_tree has
 some good information on how to get your patch landed. Let us know if
 you have any questions.
 
 Thanks again for your contribution!
 
 ~reed
 
 [0] https://bugzilla.mozilla.org/

--Ben

[1]https://bugzilla.mozilla.org/show_bug.cgi?id=557922 (NSPR)
[2]https://bugzilla.mozilla.org/show_bug.cgi?id=557925 (NSS)


pgphkQv30CI2Z.pgp
Description: PGP signature
-- 
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto