From c62f62ef6945c7376a094620e4a6fe3b08af3baa Mon Sep 17 00:00:00 2001 From: "relyea%netscape.com" Date: Wed, 5 Mar 2003 00:59:36 +0000 Subject: [PATCH] Fix memory leaks. (roll fixes from 3.7 BRANCH). --- security/nss/lib/softoken/pk11db.c | 2 ++ security/nss/lib/softoken/pk11pars.h | 2 +- security/nss/lib/softoken/pkcs11.c | 15 ++++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/security/nss/lib/softoken/pk11db.c b/security/nss/lib/softoken/pk11db.c index 6f6583c8084f..5a4906984358 100644 --- a/security/nss/lib/softoken/pk11db.c +++ b/security/nss/lib/softoken/pk11db.c @@ -451,6 +451,7 @@ secmod_EncodeData(DBT *data, char * module) pk11_argSetNewCipherFlags(&ssl[0], ciphers); SECMOD_PUTLONG(encoded->ssl,ssl[0]); SECMOD_PUTLONG(&encoded->ssl[4],ssl[1]); + if (ciphers) PORT_Free(ciphers); offset = (unsigned short) &(((secmodData *)0)->names[0]); SECMOD_PUTSHORT(encoded->nameStart,offset); @@ -496,6 +497,7 @@ loser: if (dllName) PORT_Free(dllName); if (param) PORT_Free(param); if (slotInfo) PORT_Free(slotInfo); + if (nss) PORT_Free(nss); return rv; } diff --git a/security/nss/lib/softoken/pk11pars.h b/security/nss/lib/softoken/pk11pars.h index 827932606581..5fc939f80855 100644 --- a/security/nss/lib/softoken/pk11pars.h +++ b/security/nss/lib/softoken/pk11pars.h @@ -235,7 +235,7 @@ pk11_argParseModuleSpec(char *modulespec, char **lib, char **mod, int next; modulespec = pk11_argStrip(modulespec); - *lib = *mod = *parameters = 0; + *lib = *mod = *parameters = *nss = 0; while (*modulespec) { PK11_HANDLE_STRING_ARG(modulespec,*lib,PK11_ARG_LIBRARY_PARAMETER,;) diff --git a/security/nss/lib/softoken/pkcs11.c b/security/nss/lib/softoken/pkcs11.c index ed87e0725c0f..cd5cc3d2a00c 100644 --- a/security/nss/lib/softoken/pkcs11.c +++ b/security/nss/lib/softoken/pkcs11.c @@ -3457,6 +3457,7 @@ CK_RV NSC_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, PK11Slot *slot; PK11Session *session; NSSLOWKEYDBHandle *handle; + CK_FLAGS sessionFlags; SECItem *pin; char pinStr[PK11_MAX_PIN+1]; @@ -3466,10 +3467,10 @@ CK_RV NSC_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, /* make sure the session is valid */ session = pk11_SessionFromHandle(hSession); - if (session == NULL) { - if (session == NULL) return CKR_SESSION_HANDLE_INVALID; - } + if (session == NULL) return CKR_SESSION_HANDLE_INVALID; + sessionFlags = session->info.flags; pk11_FreeSession(session); + session = NULL; /* can't log into the Netscape Slot */ if (slot->slotID == NETSCAPE_SLOT_ID) @@ -3497,7 +3498,7 @@ CK_RV NSC_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, if (nsslowkey_HasKeyDBPassword(handle) == SECFailure) { /* allow SSO's to log in only if there is not password on the * key database */ - if (((userType == CKU_SO) && (session->info.flags & CKF_RW_SESSION)) + if (((userType == CKU_SO) && (sessionFlags & CKF_RW_SESSION)) /* fips always needs to authenticate, even if there isn't a db */ || (slot->slotID == FIPS_SLOT_ID)) { /* should this be a fixed password? */ @@ -3552,9 +3553,9 @@ CK_RV NSC_Logout(CK_SESSION_HANDLE hSession) SECItem *pw = NULL; session = pk11_SessionFromHandle(hSession); - if (session == NULL) { - if (session == NULL) return CKR_SESSION_HANDLE_INVALID; - } + if (session == NULL) return CKR_SESSION_HANDLE_INVALID; + pk11_FreeSession(session); + session = NULL; if (!slot->isLoggedIn) return CKR_USER_NOT_LOGGED_IN;