From 5129c5a06034a6b45dcd0ecc86d77bd122c156fd Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Wed, 9 Dec 2015 08:22:24 +0100 Subject: [PATCH] Fixed memory leaks --- src/pkcs11/framework-pkcs15.c | 1 + src/pkcs11/pkcs11-global.c | 2 +- src/pkcs11/slot.c | 5 ++++- src/tools/pkcs11-tool.c | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pkcs11/framework-pkcs15.c b/src/pkcs11/framework-pkcs15.c index e4962bf9..e1035501 100644 --- a/src/pkcs11/framework-pkcs15.c +++ b/src/pkcs11/framework-pkcs15.c @@ -1391,6 +1391,7 @@ static CK_RV pkcs15_release_token(struct sc_pkcs11_card *p11card, void *fw_token) { sc_log(context, "pkcs15_release_token() not implemented"); + free(fw_token); return CKR_FUNCTION_REJECTED; } diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index c492392f..97fd5d49 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -635,7 +635,7 @@ CK_RV C_InitToken(CK_SLOT_ID slotID, } } - rv = slot->p11card->framework->init_token(slot,slot->fw_data, pPin, ulPinLen, pLabel); + rv = slot->p11card->framework->init_token(slot, slot->fw_data, pPin, ulPinLen, pLabel); if (rv == CKR_OK) { /* Now we should re-bind all tokens so they get the * corresponding function vector and flags */ diff --git a/src/pkcs11/slot.c b/src/pkcs11/slot.c index 6806da13..072b42b4 100644 --- a/src/pkcs11/slot.c +++ b/src/pkcs11/slot.c @@ -107,6 +107,7 @@ void delete_slot(struct sc_pkcs11_slot *slot) { if (slot) { list_destroy(&slot->objects); + list_destroy(&slot->logins); list_delete(&virtual_slots, slot); free(slot); } @@ -437,8 +438,10 @@ CK_RV slot_token_removed(CK_SLOT_ID id) /* Release framework stuff */ if (slot->p11card != NULL) { if (slot->fw_data != NULL && - slot->p11card->framework != NULL && slot->p11card->framework->release_token != NULL) + slot->p11card->framework != NULL && slot->p11card->framework->release_token != NULL) { slot->p11card->framework->release_token(slot->p11card, slot->fw_data); + slot->fw_data = NULL; + } } /* Reset relevant slot properties */ diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c index 87c322b9..827e4ee9 100644 --- a/src/tools/pkcs11-tool.c +++ b/src/tools/pkcs11-tool.c @@ -974,6 +974,7 @@ static void list_slots(int tokens, int refresh, int print) rv = p11->C_GetSlotList(tokens, NULL, &p11_num_slots); if (rv != CKR_OK) p11_fatal("C_GetSlotList(NULL)", rv); + free(p11_slots); p11_slots = calloc(p11_num_slots, sizeof(CK_SLOT_ID)); if (p11_slots == NULL) { perror("calloc failed");