From e4eeba26cd86da6532c3149861dd07a215e27d8a Mon Sep 17 00:00:00 2001 From: alonbl Date: Fri, 4 Apr 2008 16:21:08 +0000 Subject: [PATCH] Fix MSVC compiler error http://www.opensc-project.org/pipermail/opensc-devel/2008-April/010997.html Thanks to Douglas E. Engert git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3459 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/pkcs11/pkcs11-global.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index f3746eb9..973b7317 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -211,7 +211,9 @@ CK_RV C_Initialize(CK_VOID_PTR pInitArgs) load_pkcs11_parameters(&sc_pkcs11_conf, context); first_free_slot = 0; - virtual_slots = malloc(sizeof (*virtual_slots) * sc_pkcs11_conf.pkcs11_max_virtual_slots); + virtual_slots = (struct sc_pkcs11_slot *)malloc( + sizeof (*virtual_slots) * sc_pkcs11_conf.pkcs11_max_virtual_slots + ); if (virtual_slots == NULL) { rv = CKR_HOST_MEMORY; goto out; @@ -320,21 +322,30 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese CK_SLOT_ID_PTR pSlotList, /* receives the array of slot IDs */ CK_ULONG_PTR pulCount) /* receives the number of slots */ { - CK_SLOT_ID found[sc_pkcs11_conf.pkcs11_max_virtual_slots]; + CK_SLOT_ID_PTR found = NULL; int i; CK_ULONG numMatches; sc_pkcs11_slot_t *slot; CK_RV rv; - rv = sc_pkcs11_lock(); - if (rv != CKR_OK) + if ((rv = sc_pkcs11_lock()) != CKR_OK) { return rv; + } if (pulCount == NULL_PTR) { rv = CKR_ARGUMENTS_BAD; goto out; } + if ( + (found = (CK_SLOT_ID_PTR)malloc ( + sizeof (*found) * sc_pkcs11_conf.pkcs11_max_virtual_slots + )) == NULL + ) { + rv = CKR_HOST_MEMORY; + goto out; + } + sc_debug(context, "Getting slot listing\n"); card_detect_all(); @@ -366,7 +377,12 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese sc_debug(context, "returned %d slots\n", numMatches); -out: sc_pkcs11_unlock(); +out: + if (found != NULL) { + free (found); + found = NULL; + } + sc_pkcs11_unlock(); return rv; }