Changeset 3459 for trunk/src

Show
Ignore:
Timestamp:
04/04/08 16:21:08 (9 months ago)
Author:
alonbl
Message:

Fix MSVC compiler error

http://www.opensc-project.org/pipermail/opensc-devel/2008-April/010997.html

Thanks to Douglas E. Engert

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/pkcs11/pkcs11-global.c

    r3405 r3459  
    212212 
    213213        first_free_slot = 0; 
    214         virtual_slots = malloc(sizeof (*virtual_slots) * sc_pkcs11_conf.pkcs11_max_virtual_slots); 
     214        virtual_slots = (struct sc_pkcs11_slot *)malloc( 
     215                sizeof (*virtual_slots) * sc_pkcs11_conf.pkcs11_max_virtual_slots 
     216        ); 
    215217        if (virtual_slots == NULL) { 
    216218                rv = CKR_HOST_MEMORY; 
     
    321323                    CK_ULONG_PTR   pulCount)      /* receives the number of slots */ 
    322324{ 
    323         CK_SLOT_ID found[sc_pkcs11_conf.pkcs11_max_virtual_slots]; 
     325        CK_SLOT_ID_PTR found = NULL; 
    324326        int i; 
    325327        CK_ULONG numMatches; 
     
    327329        CK_RV rv; 
    328330 
    329         rv = sc_pkcs11_lock(); 
    330         if (rv != CKR_OK) 
    331                 return rv; 
     331        if ((rv = sc_pkcs11_lock()) != CKR_OK) { 
     332                return rv; 
     333        } 
    332334 
    333335        if (pulCount == NULL_PTR) { 
    334336                rv = CKR_ARGUMENTS_BAD; 
     337                goto out; 
     338        } 
     339 
     340        if ( 
     341                (found = (CK_SLOT_ID_PTR)malloc ( 
     342                        sizeof (*found) * sc_pkcs11_conf.pkcs11_max_virtual_slots 
     343                )) == NULL 
     344        ) { 
     345                rv = CKR_HOST_MEMORY; 
    335346                goto out; 
    336347        } 
     
    367378        sc_debug(context, "returned %d slots\n", numMatches); 
    368379 
    369 out:    sc_pkcs11_unlock(); 
     380out: 
     381        if (found != NULL) { 
     382                free (found); 
     383                found = NULL; 
     384        } 
     385        sc_pkcs11_unlock(); 
    370386        return rv; 
    371387}