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 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

NSS_Init failure

2010-02-16 Thread Ben Boeckel
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Hi,

I am working on a project that requires hashing data. Unfortunately, I 
have been unable to get NSS to return a valid context for hashing. Here 
is the initialization code:

62 void chasm :: mylib_init()
- -   63 {
|   64 chasm_init_data.s_nspr_inited = PR_FALSE;
|   65 chasm_init_data.s_nss_inited = PR_FALSE;
|   66 
|   67 if (!PR_Initialized())
|-  68 {
||  69 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
||  70 
||  71 if (!PR_Initialized())
||  72 _nss_error();
||  73 
||  74 chasm_init_data.s_nspr_inited = PR_TRUE;
||  75 }
|   76 
|   77 if (!NSS_IsInitialized())
|-  78 {
||  79 SECStatus status = NSS_Init(NULL);
||  80 
||  81 if (status != SECSuccess)
||  82 _nss_error();
||  83 
||  84 chasm_init_data.s_nss_inited = PR_TRUE;
||  85 }
|   86 }

Note: _nss_error() throws an exception.

The initialization of NSS fails (nothing is in PR_GetErrorText however). 
We plan on using SSL later, so a full NSS stack is necessary (saw an 
earlier post that pkcs#12 would do it, though to be honest I didn't see 
anything about how to hash with it in the docs). Any hints? Thanks in 
advance.

- --Ben
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)

iQIbBAEBCAAGBQJLey/pAAoJEKaxavVX4C1XgycP9iOLylnAAClcAJCr8n8oaOm9
IDlM2O/AwQNuafnW4nHJvFOURv4aqrcRh3QNSK8DUUl6viWT70pMCQ5xIATgKptL
QtqW9L9PjjLPdyb5mvwyr+XVuRP7bDL3mE1VrMPO5Fn4LdSWG5YwMH5al9nsCsLu
Tgyr6v9QAM4D4lMXu2A+AYngFazudYvUIcH8kkGPOCynen3xs9AL22vlb7CIYacI
fcmCpCIIja6o0N+gFj+OFfDUf5vM87b7njwvftdeJSWwpZQabHeW7295d/sySA8F
GmAGzFYqHY2RFNCSG6ihtjKnUWWQR9QnhIf60UWQ2j0iRCaSEsdVryPCpnFrdFX2
14qdWrhpnqFzhqOd2bBrnSDhbMQQS7lcPUVj3RTVqIOt6C9JMs3SGFQDlZMshgsT
MxztJoh7lrUBtOzwCQrG5KNQn6ZVdpYbZMKcMFhtcL0bYWwfjq2GcZB1qMyVxw6k
aiXhbEAUHv8nzY/lcAJcgw1PPnHdbIZTy9Vx/SnE6+IYWiDK6N7CoYMmcL58Q21S
HBIGIumyKzxuyl72Lks9q3kVtc9ZxrPhofZvujfx3xbvL8f4ivVdrbqnhgJB97nj
iJMKj+zeelRBtNDcz8jCOwY83CUNAxBmMOInCmAKtIwxSJTxqg9M1c17sNRsICnq
J8zJESwlBZatdaCVzow=
=ucUj
-END PGP SIGNATURE-


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