Fix for bug 338214 . Plug reference leak in PK11_CreateContextByRawKey . r=nelson,wtchang NSS_3_11_BRANCH
authorjulien.pierre.bugs%sun.com
Wed, 17 May 2006 22:22:27 +0000
branchNSS_3_11_BRANCH
changeset 7081 513f5911f55841a786e062be031f5718246ce775
parent 7078 cced2344a5d5b7611373229db0049957d0460bed
child 7082 fbfb615d5d4cbfc9d711818d637e29319bb1c3ae
push idunknown
push userunknown
push dateunknown
reviewersnelson, wtchang
bugs338214
Fix for bug 338214 . Plug reference leak in PK11_CreateContextByRawKey . r=nelson,wtchang
security/nss/lib/pk11wrap/pk11cxt.c
--- a/security/nss/lib/pk11wrap/pk11cxt.c
+++ b/security/nss/lib/pk11wrap/pk11cxt.c
@@ -320,38 +320,43 @@ static PK11Context *pk11_CreateNewContex
  * put together the various PK11_Create_Context calls used by different
  * parts of libsec.
  */
 PK11Context *
 __PK11_CreateContextByRawKey(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,
      PK11Origin origin, CK_ATTRIBUTE_TYPE operation, SECItem *key, 
 						SECItem *param, void *wincx)
 {
-    PK11SymKey *symKey;
-    PK11Context *context;
+    PK11SymKey *symKey = NULL;
+    PK11Context *context = NULL;
 
     /* first get a slot */
     if (slot == NULL) {
 	slot = PK11_GetBestSlot(type,wincx);
 	if (slot == NULL) {
 	    PORT_SetError( SEC_ERROR_NO_MODULE );
-	    return NULL;
+	    goto loser;
 	}
     } else {
 	PK11_ReferenceSlot(slot);
     }
 
     /* now import the key */
     symKey = PK11_ImportSymKey(slot, type, origin, operation,  key, wincx);
-    if (symKey == NULL) return NULL;
+    if (symKey == NULL) goto loser;
 
     context = PK11_CreateContextBySymKey(type, operation, symKey, param);
 
-    PK11_FreeSymKey(symKey);
-    PK11_FreeSlot(slot);
+loser:
+    if (symKey) {
+        PK11_FreeSymKey(symKey);
+    }
+    if (slot) {
+        PK11_FreeSlot(slot);
+    }
 
     return context;
 }
 
 PK11Context *
 PK11_CreateContextByRawKey(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,
      PK11Origin origin, CK_ATTRIBUTE_TYPE operation, SECItem *key, 
 						SECItem *param, void *wincx)