Skip to content

Commit

Permalink
Fix small, potential leak
Browse files Browse the repository at this point in the history
  • Loading branch information
efternavn authored and mtrojnar committed Feb 27, 2020
1 parent fd866e0 commit 9540b76
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/p11_slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ int pkcs11_enumerate_slots(PKCS11_CTX *ctx, PKCS11_SLOT **slotp,
CRYPTOKI_checkerr(CKR_F_PKCS11_ENUMERATE_SLOTS, rv);

alloc_size = nslots * sizeof(PKCS11_SLOT);
if (alloc_size / sizeof(PKCS11_SLOT) != nslots) /* integer overflow */
if (alloc_size / sizeof(PKCS11_SLOT) != nslots) { /* integer overflow */
OPENSSL_free(slotid);
return -1;
}
slots = OPENSSL_malloc(alloc_size);
if (!slots)
if (!slots) {
OPENSSL_free(slotid);
return -1;
}

memset(slots, 0, nslots * sizeof(PKCS11_SLOT));
for (n = 0; n < nslots; n++) {
if (pkcs11_init_slot(ctx, &slots[n], slotid[n])) {
Expand Down

0 comments on commit 9540b76

Please sign in to comment.