Bug 1453505 - Don't leak newTemplate in pk11_copyAttributes() r=franziskus
authorTim Taubert <ttaubert@mozilla.com>
Fri, 13 Apr 2018 10:42:58 +0200
changeset 14325 7768f56506bb096892092489be9d99011b6ab750
parent 14324 e32e2755932b7c9682091187f2570065f1f411f4
child 14326 b8804e4c798956bcd12c195ee77579194f6f8aca
push id3060
push userttaubert@mozilla.com
push dateFri, 13 Apr 2018 08:43:52 +0000
reviewersfranziskus
bugs1453505
Bug 1453505 - Don't leak newTemplate in pk11_copyAttributes() r=franziskus Reviewers: franziskus Reviewed By: franziskus Bug #: 1453505 Differential Revision: https://phabricator.services.mozilla.com/D937
lib/pk11wrap/pk11merge.c
--- a/lib/pk11wrap/pk11merge.c
+++ b/lib/pk11wrap/pk11merge.c
@@ -69,43 +69,44 @@ pk11_copyAttributes(PLArenaPool *arena,
     /* if we have missing attributes, just skip them and create the object */
     if (crv == CKR_ATTRIBUTE_TYPE_INVALID) {
         CK_ULONG i, j;
         newTemplate = PORT_NewArray(CK_ATTRIBUTE, copyTemplateCount);
         if (!newTemplate) {
             return SECFailure;
         }
         /* remove the unknown attributes. If we don't have enough attributes
-	 * PK11_CreateNewObject() will fail */
+         * PK11_CreateNewObject() will fail */
         for (i = 0, j = 0; i < copyTemplateCount; i++) {
             if (copyTemplate[i].ulValueLen != -1) {
                 newTemplate[j] = copyTemplate[i];
                 j++;
             }
         }
         copyTemplate = newTemplate;
         copyTemplateCount = j;
         crv = PK11_GetAttributes(arena, sourceSlot, sourceID,
                                  copyTemplate, copyTemplateCount);
     }
     if (crv != CKR_OK) {
         PORT_SetError(PK11_MapError(crv));
+        PORT_Free(newTemplate);
         return SECFailure;
     }
     if (targetID == CK_INVALID_HANDLE) {
         /* we need to create the object */
         rv = PK11_CreateNewObject(targetSlot, CK_INVALID_SESSION,
                                   copyTemplate, copyTemplateCount, PR_TRUE, &targetID);
     } else {
         /* update the existing object with the new attributes */
         rv = pk11_setAttributes(targetSlot, targetID,
                                 copyTemplate, copyTemplateCount);
     }
     if (newTemplate) {
-        free(newTemplate);
+        PORT_Free(newTemplate);
     }
     return rv;
 }
 
 /*
  * look for a matching object across tokens.
  */
 static SECStatus