Skip to content

Commit

Permalink
Fix memory leaks when tokens are missing
Browse files Browse the repository at this point in the history
In case we have slots advertized but the driver fails to return
information or the token is not present we were leaking memory as the
slot is not added to the array and the number of slots is not
incremented.

Ensure the slot struct is freed in this case.

Signed-off-by: Simo Sorce <[email protected]>
  • Loading branch information
simo5 committed Nov 6, 2024
1 parent e064032 commit c0e9225
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ CK_RV p11prov_init_slots(P11PROV_CTX *ctx, P11PROV_SLOTS_CTX **slots)
ret = p11prov_GetSlotInfo(ctx, slotid[i], &slot->slot);
if (ret != CKR_OK || (slot->slot.flags & CKF_TOKEN_PRESENT) == 0) {
/* skip slot */
OPENSSL_free(slot);
continue;
}
ret = p11prov_GetTokenInfo(ctx, slotid[i], &slot->token);
if (ret) {
/* skip slot */
OPENSSL_free(slot);
continue;
}

Expand Down

0 comments on commit c0e9225

Please sign in to comment.