Bug 1280844 - Remove even more redundant null checks in lib/. r?mt. draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 21 Jun 2016 09:59:17 +1000
changeset 380174 50086c7e64f0cbc8f6d65320ea7db15d32c1ee6d
parent 380173 8aa601ca7d3c6ab2f7381774e759c57468d510d9
child 380175 c29f89f62bf45bf8286a4733da33c774d061ba0b
push id21158
push usernnethercote@mozilla.com
push dateMon, 20 Jun 2016 23:59:39 +0000
reviewersmt
bugs1280844
milestone50.0a1
Bug 1280844 - Remove even more redundant null checks in lib/. r?mt. MozReview-Commit-ID: tDsUZbXn2j
security/nss/lib/libpkix/pkix_pl_nss/module/pkix_pl_aiamgr.c
security/nss/lib/pk11wrap/pk11akey.c
security/nss/lib/pk11wrap/pk11obj.c
security/nss/lib/pk11wrap/pk11skey.c
security/nss/lib/pk11wrap/pk11slot.c
--- a/security/nss/lib/libpkix/pkix_pl_nss/module/pkix_pl_aiamgr.c
+++ b/security/nss/lib/libpkix/pkix_pl_nss/module/pkix_pl_aiamgr.c
@@ -361,17 +361,17 @@ pkix_pl_AIAMgr_GetHTTPCerts(
 
         } else  {
 		PKIX_ERROR(PKIX_UNSUPPORTEDVERSIONOFHTTPCLIENT);
 	}
 
 cleanup:
         /* Session and request cleanup in case of error. Passing through without cleanup
          * if interrupted by blocked IO. */
-        if (PKIX_ERROR_RECEIVED && aiaMgr) {
+        if (PKIX_ERROR_RECEIVED) {
             if (aiaMgr->client.hdata.requestSession != NULL) {
                 (*hcv1->freeFcn)(aiaMgr->client.hdata.requestSession);
                 aiaMgr->client.hdata.requestSession = NULL;
             }
             if (aiaMgr->client.hdata.serverSession != NULL) {
                 (*hcv1->freeSessionFcn)(aiaMgr->client.hdata.serverSession);
                 aiaMgr->client.hdata.serverSession = NULL;
             }
--- a/security/nss/lib/pk11wrap/pk11akey.c
+++ b/security/nss/lib/pk11wrap/pk11akey.c
@@ -808,20 +808,19 @@ PK11_GetPrivateModulusLen(SECKEYPrivateK
 	if (crv != CKR_OK) {
 	    PORT_SetError( PK11_MapError(crv) );
 	    return -1;
 	}
 	length = theTemplate.ulValueLen;
 	if ( *(unsigned char *)theTemplate.pValue == 0) {
 	    length--;
 	}
-	if (theTemplate.pValue != NULL)
-	    PORT_Free(theTemplate.pValue);
+	PORT_Free(theTemplate.pValue);
 	return (int) length;
-	
+
     case fortezzaKey:
     case dsaKey:
     case dhKey:
     default:
 	break;
     }
     if (theTemplate.pValue != NULL)
 	PORT_Free(theTemplate.pValue);
--- a/security/nss/lib/pk11wrap/pk11obj.c
+++ b/security/nss/lib/pk11wrap/pk11obj.c
@@ -1239,20 +1239,18 @@ PK11_UnwrapPrivKey(PK11SlotInfo *slot, P
 	    PK11_ExitSlotMonitor(slot);
 	}
 	PK11_FreeSymKey(newKey);
 	newKey = NULL;
     } else {
 	crv = CKR_FUNCTION_NOT_SUPPORTED;
     }
 
-    if (ck_id) {
-	SECITEM_FreeItem(ck_id, PR_TRUE);
-	ck_id = NULL;
-    }
+    SECITEM_FreeItem(ck_id, PR_TRUE);
+    ck_id = NULL;
 
     if (crv != CKR_OK) {
 	/* we couldn't unwrap the key, use the internal module to do the
 	 * unwrap, then load the new key into the token */
 	 PK11SlotInfo *int_slot = PK11_GetInternalSlot();
 
 	if (int_slot && (slot != int_slot)) {
 	    SECKEYPrivateKey *privKey = PK11_UnwrapPrivKey(int_slot,
--- a/security/nss/lib/pk11wrap/pk11skey.c
+++ b/security/nss/lib/pk11wrap/pk11skey.c
@@ -1770,18 +1770,17 @@ static PK11SymKey *pk11_ANSIX963Derive(P
     }
 
     PORT_ZFree(buffer, bufferLen);
     if (newSharedSecret != NULL)
 	PK11_FreeSymKey(newSharedSecret);
     return intermediateResult;
 
 loser:
-    if (buffer != NULL)
-	PORT_ZFree(buffer, bufferLen);
+    PORT_ZFree(buffer, bufferLen);
     if (newSharedSecret != NULL)
 	PK11_FreeSymKey(newSharedSecret);
     if (intermediateResult != NULL)
 	PK11_FreeSymKey(intermediateResult);
     return NULL;
 }
 
 /*
--- a/security/nss/lib/pk11wrap/pk11slot.c
+++ b/security/nss/lib/pk11wrap/pk11slot.c
@@ -555,20 +555,18 @@ PK11_FindSlotsByNames(const char *dllNam
                     rv = SECFailure;
                     break;
                 }
                 if ((PR_FALSE == presentOnly || PK11_IsPresent(tmpSlot)) &&
                     ( (!tokenName) ||
                       (0==PORT_Strcmp(tmpSlot->token_name, tokenName)) ) &&
                     ( (!slotName) ||
                       (0==PORT_Strcmp(tmpSlot->slot_name, slotName)) ) ) {
-                    if (tmpSlot) {
-                        PK11_AddSlotToList(slotList, tmpSlot, PR_TRUE);
-                        slotcount++;
-                    }
+                    PK11_AddSlotToList(slotList, tmpSlot, PR_TRUE);
+                    slotcount++;
                 }
             }
         }
     }
     SECMOD_ReleaseReadLock(moduleLock);
 
     if ( (0 == slotcount) || (SECFailure == rv) ) {
         PORT_SetError(SEC_ERROR_NO_TOKEN);