Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks when tokens are missing #463

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,23 @@ CK_RV p11prov_init_slots(P11PROV_CTX *ctx, P11PROV_SLOTS_CTX **slots)
ret = CKR_HOST_MEMORY;
goto done;
}
sctx->slots[sctx->num] = slot;

ret = p11prov_GetSlotInfo(ctx, slotid[i], &slot->slot);
if (ret != CKR_OK || (slot->slot.flags & CKF_TOKEN_PRESENT) == 0) {
/* skip slot */
OPENSSL_free(slot);
simo5 marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
ret = p11prov_GetTokenInfo(ctx, slotid[i], &slot->token);
if (ret) {
/* skip slot */
OPENSSL_free(slot);
continue;
}

sctx->slots[sctx->num] = slot;
sctx->num++;
simo5 marked this conversation as resolved.
Show resolved Hide resolved

trim(slot->slot.slotDescription);
trim(slot->slot.manufacturerID);
trim(slot->token.label);
Expand Down Expand Up @@ -243,8 +247,6 @@ CK_RV p11prov_init_slots(P11PROV_CTX *ctx, P11PROV_SLOTS_CTX **slots)

P11PROV_debug_slot(ctx, slot->id, &slot->slot, &slot->token,
slot->mechs, slot->nmechs, slot->profiles);

sctx->num++;
}

done:
Expand Down Expand Up @@ -348,9 +350,6 @@ void p11prov_free_slots(P11PROV_SLOTS_CTX *sctx)
err);
return;
}
if (sctx->num == 0) {
return;
}
for (int i = 0; i < sctx->num; i++) {
p11prov_session_pool_free(sctx->slots[i]->pool);
p11prov_obj_pool_free(sctx->slots[i]->objects);
Expand Down
Loading