From 9c3cb54c8cd0826f90df10fd2978872f080be7b4 Mon Sep 17 00:00:00 2001 From: "rrelyea%redhat.com" Date: Fri, 15 Jun 2007 20:37:56 +0000 Subject: [PATCH] Again fix memory leaks, but also fix the latent bug in pcertdb shutdown leak plugging exposed. bob r=glen git-svn-id: svn://10.0.0.236/trunk@228135 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/security/nss/lib/softoken/legacydb/lginit.c | 3 ++- mozilla/security/nss/lib/softoken/legacydb/lgutil.c | 4 ++-- mozilla/security/nss/lib/softoken/legacydb/pcertdb.c | 6 +++++- mozilla/security/nss/lib/softoken/lgglue.c | 7 +++++-- mozilla/security/nss/lib/softoken/sftkdb.c | 4 +++- mozilla/security/nss/lib/softoken/sftkpars.c | 11 +++++++++-- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/mozilla/security/nss/lib/softoken/legacydb/lginit.c b/mozilla/security/nss/lib/softoken/legacydb/lginit.c index 55442266888..90497f8bf6c 100644 --- a/mozilla/security/nss/lib/softoken/legacydb/lginit.c +++ b/mozilla/security/nss/lib/softoken/legacydb/lginit.c @@ -36,7 +36,7 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -/* $Id: lginit.c,v 1.5 2007-06-15 03:51:08 rrelyea%redhat.com Exp $ */ +/* $Id: lginit.c,v 1.6 2007-06-15 20:37:56 rrelyea%redhat.com Exp $ */ #include "lowkeyi.h" #include "pcert.h" @@ -460,6 +460,7 @@ CK_RV lg_Close(SDB *sdb) { LGPrivate *lgdb_p = (LGPrivate *)sdb->private; + lg_ClearTokenKeyHashTable(sdb); if (lgdb_p) { if (lgdb_p->certDB) { nsslowcert_ClosePermCertDB(lgdb_p->certDB); diff --git a/mozilla/security/nss/lib/softoken/legacydb/lgutil.c b/mozilla/security/nss/lib/softoken/legacydb/lgutil.c index 6bb6902f59e..f474b5fea86 100644 --- a/mozilla/security/nss/lib/softoken/legacydb/lgutil.c +++ b/mozilla/security/nss/lib/softoken/legacydb/lgutil.c @@ -296,13 +296,13 @@ lg_freeHashItem(PLHashEntry* entry, PRIntn index, void *arg) } CK_RV -LG_ClearTokenKeyHashTable(SDB *sdb) +lg_ClearTokenKeyHashTable(SDB *sdb) { PLHashTable *hashTable; lg_DBLock(sdb); hashTable= lg_GetHashTable(sdb); PL_HashTableEnumerateEntries(hashTable, lg_freeHashItem, NULL); - lg_DBLock(sdb); + lg_DBUnlock(sdb); return CKR_OK; } diff --git a/mozilla/security/nss/lib/softoken/legacydb/pcertdb.c b/mozilla/security/nss/lib/softoken/legacydb/pcertdb.c index be7184653e5..b7d19ee3c21 100644 --- a/mozilla/security/nss/lib/softoken/legacydb/pcertdb.c +++ b/mozilla/security/nss/lib/softoken/legacydb/pcertdb.c @@ -37,7 +37,7 @@ /* * Permanent Certificate database handling code * - * $Id: pcertdb.c,v 1.4 2007-06-15 03:51:08 rrelyea%redhat.com Exp $ + * $Id: pcertdb.c,v 1.5 2007-06-15 20:37:56 rrelyea%redhat.com Exp $ */ #include "lowkeyti.h" #include "pcert.h" @@ -4462,6 +4462,7 @@ nsslowcert_ClosePermCertDB(NSSLOWCERTCertDBHandle *handle) PZ_DestroyMonitor(handle->dbMon); handle->dbMon = NULL; } + PORT_Free(handle); } return; } @@ -5263,6 +5264,9 @@ nsslowcert_SaveSMimeProfile(NSSLOWCERTCertDBHandle *dbhandle, char *emailAddr, void nsslowcert_DestroyFreeLists(void) { + if (freeListLock == NULL) { + return; + } DestroyCertEntryFreeList(); DestroyTrustFreeList(); DestroyCertFreeList(); diff --git a/mozilla/security/nss/lib/softoken/lgglue.c b/mozilla/security/nss/lib/softoken/lgglue.c index a20a1804f1e..bd7b4d25b13 100644 --- a/mozilla/security/nss/lib/softoken/lgglue.c +++ b/mozilla/security/nss/lib/softoken/lgglue.c @@ -172,9 +172,12 @@ sftkdb_LoadLibrary(const char *libname) PORT_Free(trueParentLibPath); } #endif - PORT_Free(parentLibPath); done: + if (parentLibPath) { + PORT_Free(parentLibPath); + } + /* still couldn't load it, try the generic path */ if (!lib) { PRLibSpec libSpec; @@ -322,7 +325,7 @@ CK_RV sftkdbCall_Shutdown(void) { CK_RV crv = CKR_OK; - if (legacy_glue_lib) { + if (!legacy_glue_lib) { return CKR_OK; } if (legacy_glue_shutdown) { diff --git a/mozilla/security/nss/lib/softoken/sftkdb.c b/mozilla/security/nss/lib/softoken/sftkdb.c index 889e9244e45..ebb0e516007 100644 --- a/mozilla/security/nss/lib/softoken/sftkdb.c +++ b/mozilla/security/nss/lib/softoken/sftkdb.c @@ -557,7 +557,6 @@ sftkdb_GetAttributeValue(SFTKDBHandle *handle, CK_OBJECT_HANDLE object_id, CK_ATTRIBUTE *ntemplate; unsigned char *data = NULL; SDB *db; - int i; if (handle == NULL) { return CKR_GENERAL_ERROR; @@ -697,6 +696,9 @@ sftkdb_CloseDB(SFTKDBHandle *handle) if (handle->db) { (*handle->db->sdb_Close)(handle->db); } + if (handle->passwordLock) { + PZ_DestroyLock(handle->passwordLock); + } PORT_Free(handle); return CKR_OK; } diff --git a/mozilla/security/nss/lib/softoken/sftkpars.c b/mozilla/security/nss/lib/softoken/sftkpars.c index 96189937eeb..a8749482ee3 100644 --- a/mozilla/security/nss/lib/softoken/sftkpars.c +++ b/mozilla/security/nss/lib/softoken/sftkpars.c @@ -590,8 +590,9 @@ sftk_getSecmodName(char *param, SDBType *dbType, char **appName, } *rw = PR_TRUE; - if (sftk_argHasFlag("flags","readOnly",save_params) || - sftk_argHasFlag("flags","noModDB",save_params)) *rw = PR_FALSE; + if (sftk_argHasFlag("flags","readOnly",save_params)) { + *rw = PR_FALSE; + } if (!secmodName || *secmodName == '\0') { if (secmodName) PORT_Free(secmodName); @@ -601,6 +602,12 @@ sftk_getSecmodName(char *param, SDBType *dbType, char **appName, *filename = secmodName; lconfigdir = sftk_EvaluateConfigDir(configdir, dbType, appName); + if (sftk_argHasFlag("flags","noModDB",save_params)) { + /* there isn't a module db, don't load the legacy support */ + *dbType = SDB_SQL; + *rw = PR_FALSE; + } + /* only use the renamed secmod for legacy databases */ if ((*dbType != SDB_LEGACY) && (*dbType != SDB_MULTIACCESS)) { secmodName="pkcs11.txt";