From c0e92253a258eb5d8a74d1a1283b09273125b1c9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 6 Nov 2024 10:57:58 -0500 Subject: [PATCH] Fix memory leaks when tokens are missing 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 --- src/slot.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slot.c b/src/slot.c index ddab71ec..8974fb3b 100644 --- a/src/slot.c +++ b/src/slot.c @@ -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; }