pkcs11: use calloc instead of malloc; remove obsolete malloc.h references.

This commit is contained in:
Martin Paljak 2013-03-15 22:12:25 +02:00
parent 3b4f7b9ff7
commit 32ed309037
7 changed files with 9 additions and 14 deletions

View File

@ -243,7 +243,7 @@ AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_ASSERT
AC_CHECK_HEADERS([ \
errno.h fcntl.h malloc.h stdlib.h \
errno.h fcntl.h stdlib.h \
inttypes.h string.h strings.h \
sys/time.h unistd.h getopt.h sys/mman.h
])

View File

@ -4052,13 +4052,12 @@ static int pkcs15_skey_get_value(struct sc_pkcs11_session *session,
* but for now we only work with session objects
* derived from other keys
*/
skey_data= malloc(sizeof(struct sc_pkcs15_skey));
skey_data= calloc(1, sizeof(struct sc_pkcs15_skey));
if (skey_data == NULL)
return SC_ERROR_OUT_OF_MEMORY;
memset(skey_data, 0, sizeof(struct sc_pkcs15_skey));
if (skey->value && skey->value->data_len) {
skey_data->data = malloc(skey_data->data_len);
skey_data->data = calloc(1, skey_data->data_len);
if (skey_data->data == NULL) {
free(skey_data);
return SC_ERROR_OUT_OF_MEMORY;

View File

@ -673,7 +673,7 @@ sc_pkcs11_verify_final(sc_pkcs11_operation_t *operation,
rv = key->ops->get_attribute(operation->session, key, &attr);
if (rv != CKR_OK)
return rv;
pubkey_value = malloc(attr.ulValueLen);
pubkey_value = calloc(1, attr.ulValueLen);
attr.pValue = pubkey_value;
rv = key->ops->get_attribute(operation->session, key, &attr);
if (rv != CKR_OK)

View File

@ -420,7 +420,7 @@ CK_RV sc_pkcs11_verify_data(const unsigned char *pubkey, int pubkey_len,
if (rsa == NULL)
return CKR_DEVICE_MEMORY;
rsa_out = malloc(RSA_size(rsa));
rsa_out = calloc(1, RSA_size(rsa));
if (rsa_out == NULL) {
RSA_free(rsa);
return CKR_DEVICE_MEMORY;

View File

@ -42,7 +42,7 @@ extern CK_FUNCTION_LIST pkcs11_function_list;
#include <pthread.h>
CK_RV mutex_create(void **mutex)
{
pthread_mutex_t *m = malloc(sizeof(*mutex));
pthread_mutex_t *m = calloc(1, sizeof(*mutex));
if (m == NULL)
return CKR_GENERAL_ERROR;;
pthread_mutex_init(m, NULL);
@ -80,7 +80,7 @@ CK_RV mutex_create(void **mutex)
{
CRITICAL_SECTION *m;
m = malloc(sizeof(*m));
m = calloc(1, sizeof(*m));
if (m == NULL)
return CKR_GENERAL_ERROR;
InitializeCriticalSection(m);
@ -385,7 +385,7 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
card_detect_all();
found = malloc(list_size(&virtual_slots) * sizeof(CK_SLOT_ID));
found = calloc(list_size(&virtual_slots), sizeof(CK_SLOT_ID));
if (found == NULL) {
rv = CKR_HOST_MEMORY;

View File

@ -1352,7 +1352,7 @@ int sc_pkcs11_any_cmp_attribute(struct sc_pkcs11_session *session, void *ptr, CK
if (temp_attr.ulValueLen <= sizeof(temp1))
temp_attr.pValue = temp1;
else {
temp2 = malloc(temp_attr.ulValueLen);
temp2 = calloc(1, temp_attr.ulValueLen);
if (temp2 == NULL)
return 0;
temp_attr.pValue = temp2;

View File

@ -23,10 +23,6 @@
#include "config.h"
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include "libopensc/opensc.h"
#include "libopensc/pkcs15.h"
#include "libopensc/log.h"