aboutsummaryrefslogtreecommitdiffstats
path: root/libcacard
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-08-20 22:09:37 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2011-08-20 23:01:08 -0500
commit7267c0947d7e8ae5dff7bafd932c3bc285f43e5c (patch)
tree9aa05d6e05ed83e67bf014f6745a3081b8407dc5 /libcacard
parent14015304b662e8f8ccce46c5a6927af6a14c510b (diff)
Use glib memory allocation and free functions
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'libcacard')
-rw-r--r--libcacard/cac.c16
-rw-r--r--libcacard/card_7816.c28
-rw-r--r--libcacard/event.c4
-rw-r--r--libcacard/vcard.c20
-rw-r--r--libcacard/vcard_emul_nss.c48
-rw-r--r--libcacard/vreader.c14
-rw-r--r--libcacard/vscclient.c2
7 files changed, 66 insertions, 66 deletions
diff --git a/libcacard/cac.c b/libcacard/cac.c
index f34f63ac7..f4b0b1b05 100644
--- a/libcacard/cac.c
+++ b/libcacard/cac.c
@@ -98,7 +98,7 @@ cac_applet_pki_reset(VCard *card, int channel)
pki_applet->cert_buffer = NULL;
if (pki_applet->sign_buffer) {
- qemu_free(pki_applet->sign_buffer);
+ g_free(pki_applet->sign_buffer);
pki_applet->sign_buffer = NULL;
}
pki_applet->cert_buffer_len = 0;
@@ -166,7 +166,7 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
sign_buffer = realloc(pki_applet->sign_buffer,
pki_applet->sign_buffer_len+size);
if (sign_buffer == NULL) {
- qemu_free(pki_applet->sign_buffer);
+ g_free(pki_applet->sign_buffer);
pki_applet->sign_buffer = NULL;
pki_applet->sign_buffer_len = 0;
*response = vcard_make_response(
@@ -204,7 +204,7 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
VCARD7816_STATUS_ERROR_P1_P2_INCORRECT);
break;
}
- qemu_free(sign_buffer);
+ g_free(sign_buffer);
pki_applet->sign_buffer = NULL;
pki_applet->sign_buffer_len = 0;
return VCARD_DONE;
@@ -271,15 +271,15 @@ cac_delete_pki_applet_private(VCardAppletPrivate *applet_private)
}
pki_applet_data = &(applet_private->u.pki_data);
if (pki_applet_data->cert != NULL) {
- qemu_free(pki_applet_data->cert);
+ g_free(pki_applet_data->cert);
}
if (pki_applet_data->sign_buffer != NULL) {
- qemu_free(pki_applet_data->sign_buffer);
+ g_free(pki_applet_data->sign_buffer);
}
if (pki_applet_data->key != NULL) {
vcard_emul_delete_key(pki_applet_data->key);
}
- qemu_free(applet_private);
+ g_free(applet_private);
}
static VCardAppletPrivate *
@@ -288,7 +288,7 @@ cac_new_pki_applet_private(const unsigned char *cert,
{
CACPKIAppletData *pki_applet_data = NULL;
VCardAppletPrivate *applet_private = NULL;
- applet_private = (VCardAppletPrivate *)qemu_malloc(sizeof(VCardAppletPrivate));
+ applet_private = (VCardAppletPrivate *)g_malloc(sizeof(VCardAppletPrivate));
pki_applet_data = &(applet_private->u.pki_data);
pki_applet_data->cert_buffer = NULL;
@@ -296,7 +296,7 @@ cac_new_pki_applet_private(const unsigned char *cert,
pki_applet_data->sign_buffer = NULL;
pki_applet_data->sign_buffer_len = 0;
pki_applet_data->key = NULL;
- pki_applet_data->cert = (unsigned char *)qemu_malloc(cert_len+1);
+ pki_applet_data->cert = (unsigned char *)g_malloc(cert_len+1);
/*
* if we want to support compression, then we simply change the 0 to a 1
* and compress the cert data with libz
diff --git a/libcacard/card_7816.c b/libcacard/card_7816.c
index eeea84989..9fd59d4a5 100644
--- a/libcacard/card_7816.c
+++ b/libcacard/card_7816.c
@@ -51,8 +51,8 @@ vcard_response_new_data(unsigned char *buf, int len)
{
VCardResponse *new_response;
- new_response = (VCardResponse *)qemu_malloc(sizeof(VCardResponse));
- new_response->b_data = qemu_malloc(len + 2);
+ new_response = (VCardResponse *)g_malloc(sizeof(VCardResponse));
+ new_response->b_data = g_malloc(len + 2);
memcpy(new_response->b_data, buf, len);
new_response->b_total_len = len+2;
new_response->b_len = len;
@@ -132,7 +132,7 @@ vcard_response_new_status(vcard_7816_status_t status)
{
VCardResponse *new_response;
- new_response = (VCardResponse *)qemu_malloc(sizeof(VCardResponse));
+ new_response = (VCardResponse *)g_malloc(sizeof(VCardResponse));
new_response->b_data = &new_response->b_sw1;
new_response->b_len = 0;
new_response->b_total_len = 2;
@@ -149,7 +149,7 @@ vcard_response_new_status_bytes(unsigned char sw1, unsigned char sw2)
{
VCardResponse *new_response;
- new_response = (VCardResponse *)qemu_malloc(sizeof(VCardResponse));
+ new_response = (VCardResponse *)g_malloc(sizeof(VCardResponse));
new_response->b_data = &new_response->b_sw1;
new_response->b_len = 0;
new_response->b_total_len = 2;
@@ -173,19 +173,19 @@ vcard_response_delete(VCardResponse *response)
case VCARD_MALLOC:
/* everything was malloc'ed */
if (response->b_data) {
- qemu_free(response->b_data);
+ g_free(response->b_data);
}
- qemu_free(response);
+ g_free(response);
break;
case VCARD_MALLOC_DATA:
/* only the data buffer was malloc'ed */
if (response->b_data) {
- qemu_free(response->b_data);
+ g_free(response->b_data);
}
break;
case VCARD_MALLOC_STRUCT:
/* only the structure was malloc'ed */
- qemu_free(response);
+ g_free(response);
break;
case VCARD_STATIC:
break;
@@ -336,18 +336,18 @@ vcard_apdu_new(unsigned char *raw_apdu, int len, vcard_7816_status_t *status)
return NULL;
}
- new_apdu = (VCardAPDU *)qemu_malloc(sizeof(VCardAPDU));
- new_apdu->a_data = qemu_malloc(len);
+ new_apdu = (VCardAPDU *)g_malloc(sizeof(VCardAPDU));
+ new_apdu->a_data = g_malloc(len);
memcpy(new_apdu->a_data, raw_apdu, len);
new_apdu->a_len = len;
*status = vcard_apdu_set_class(new_apdu);
if (*status != VCARD7816_STATUS_SUCCESS) {
- qemu_free(new_apdu);
+ g_free(new_apdu);
return NULL;
}
*status = vcard_apdu_set_length(new_apdu);
if (*status != VCARD7816_STATUS_SUCCESS) {
- qemu_free(new_apdu);
+ g_free(new_apdu);
new_apdu = NULL;
}
return new_apdu;
@@ -360,9 +360,9 @@ vcard_apdu_delete(VCardAPDU *apdu)
return;
}
if (apdu->a_data) {
- qemu_free(apdu->a_data);
+ g_free(apdu->a_data);
}
- qemu_free(apdu);
+ g_free(apdu);
}
diff --git a/libcacard/event.c b/libcacard/event.c
index bb2f9219f..61923761c 100644
--- a/libcacard/event.c
+++ b/libcacard/event.c
@@ -17,7 +17,7 @@ vevent_new(VEventType type, VReader *reader, VCard *card)
{
VEvent *new_vevent;
- new_vevent = (VEvent *)qemu_malloc(sizeof(VEvent));
+ new_vevent = (VEvent *)g_malloc(sizeof(VEvent));
new_vevent->next = NULL;
new_vevent->type = type;
new_vevent->reader = vreader_reference(reader);
@@ -34,7 +34,7 @@ vevent_delete(VEvent *vevent)
}
vreader_free(vevent->reader);
vcard_free(vevent->card);
- qemu_free(vevent);
+ g_free(vevent);
}
/*
diff --git a/libcacard/vcard.c b/libcacard/vcard.c
index 29b4cce6e..b02556ee0 100644
--- a/libcacard/vcard.c
+++ b/libcacard/vcard.c
@@ -37,8 +37,8 @@ vcard_buffer_response_new(unsigned char *buffer, int size)
{
VCardBufferResponse *new_buffer;
- new_buffer = (VCardBufferResponse *)qemu_malloc(sizeof(VCardBufferResponse));
- new_buffer->buffer = (unsigned char *)qemu_malloc(size);
+ new_buffer = (VCardBufferResponse *)g_malloc(sizeof(VCardBufferResponse));
+ new_buffer->buffer = (unsigned char *)g_malloc(size);
memcpy(new_buffer->buffer, buffer, size);
new_buffer->buffer_len = size;
new_buffer->current = new_buffer->buffer;
@@ -53,9 +53,9 @@ vcard_buffer_response_delete(VCardBufferResponse *buffer_response)
return;
}
if (buffer_response->buffer) {
- qemu_free(buffer_response->buffer);
+ g_free(buffer_response->buffer);
}
- qemu_free(buffer_response);
+ g_free(buffer_response);
}
@@ -102,14 +102,14 @@ vcard_new_applet(VCardProcessAPDU applet_process_function,
{
VCardApplet *applet;
- applet = (VCardApplet *)qemu_malloc(sizeof(VCardApplet));
+ applet = (VCardApplet *)g_malloc(sizeof(VCardApplet));
applet->next = NULL;
applet->applet_private = NULL;
applet->applet_private_free = NULL;
applet->process_apdu = applet_process_function;
applet->reset_applet = applet_reset_function;
- applet->aid = qemu_malloc(aid_len);
+ applet->aid = g_malloc(aid_len);
memcpy(applet->aid, aid, aid_len);
applet->aid_len = aid_len;
return applet;
@@ -127,10 +127,10 @@ vcard_delete_applet(VCardApplet *applet)
applet->applet_private = NULL;
}
if (applet->aid) {
- qemu_free(applet->aid);
+ g_free(applet->aid);
applet->aid = NULL;
}
- qemu_free(applet);
+ g_free(applet);
}
/* accessor */
@@ -151,7 +151,7 @@ vcard_new(VCardEmul *private, VCardEmulFree private_free)
VCard *new_card;
int i;
- new_card = (VCard *)qemu_malloc(sizeof(VCard));
+ new_card = (VCard *)g_malloc(sizeof(VCard));
new_card->applet_list = NULL;
for (i = 0; i < MAX_CHANNEL; i++) {
new_card->current_applet[i] = NULL;
@@ -199,7 +199,7 @@ vcard_free(VCard *vcard)
vcard_delete_applet(current_applet);
}
vcard_buffer_response_delete(vcard->vcard_buffer_response);
- qemu_free(vcard);
+ g_free(vcard);
return;
}
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index 84fc49026..397485c75 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -94,9 +94,9 @@ vcard_emul_alloc_arrays(unsigned char ***certsp, int **cert_lenp,
*certsp = NULL;
*cert_lenp = NULL;
*keysp = NULL;
- *certsp = (unsigned char **)qemu_malloc(sizeof(unsigned char *)*cert_count);
- *cert_lenp = (int *)qemu_malloc(sizeof(int)*cert_count);
- *keysp = (VCardKey **)qemu_malloc(sizeof(VCardKey *)*cert_count);
+ *certsp = (unsigned char **)g_malloc(sizeof(unsigned char *)*cert_count);
+ *cert_lenp = (int *)g_malloc(sizeof(int)*cert_count);
+ *keysp = (VCardKey **)g_malloc(sizeof(VCardKey *)*cert_count);
return PR_TRUE;
}
@@ -140,7 +140,7 @@ vcard_emul_make_key(PK11SlotInfo *slot, CERTCertificate *cert)
{
VCardKey *key;
- key = (VCardKey *)qemu_malloc(sizeof(VCardKey));
+ key = (VCardKey *)g_malloc(sizeof(VCardKey));
key->slot = PK11_ReferenceSlot(slot);
key->cert = CERT_DupCertificate(cert);
/* NOTE: if we aren't logged into the token, this could return NULL */
@@ -244,7 +244,7 @@ vcard_emul_rsa_op(VCard *card, VCardKey *key,
/* be able to handle larger keys if necessariy */
bp = &buf[0];
if (sizeof(buf) < signature_len) {
- bp = qemu_malloc(signature_len);
+ bp = g_malloc(signature_len);
}
/*
@@ -348,7 +348,7 @@ vcard_emul_rsa_op(VCard *card, VCardKey *key,
key->failedX509 = VCardEmulTrue;
cleanup:
if (bp != buf) {
- qemu_free(bp);
+ g_free(bp);
}
return ret;
}
@@ -382,7 +382,7 @@ vcard_emul_login(VCard *card, unsigned char *pin, int pin_len)
* to handle multiple guests from one process, then we would need to keep
* a lot of extra state in our card structure
* */
- pin_string = qemu_malloc(pin_len+1);
+ pin_string = g_malloc(pin_len+1);
memcpy(pin_string, pin, pin_len);
pin_string[pin_len] = 0;
@@ -394,7 +394,7 @@ vcard_emul_login(VCard *card, unsigned char *pin, int pin_len)
rv = PK11_Authenticate(slot, PR_FALSE, pin_string);
memset(pin_string, 0, pin_len); /* don't let the pin hang around in memory
to be snooped */
- qemu_free(pin_string);
+ g_free(pin_string);
if (rv == SECSuccess) {
return VCARD7816_STATUS_SUCCESS;
}
@@ -452,7 +452,7 @@ vreader_emul_new(PK11SlotInfo *slot, VCardEmulType type, const char *params)
{
VReaderEmul *new_reader_emul;
- new_reader_emul = (VReaderEmul *)qemu_malloc(sizeof(VReaderEmul));
+ new_reader_emul = (VReaderEmul *)g_malloc(sizeof(VReaderEmul));
new_reader_emul->slot = PK11_ReferenceSlot(slot);
new_reader_emul->default_type = type;
@@ -473,9 +473,9 @@ vreader_emul_delete(VReaderEmul *vreader_emul)
PK11_FreeSlot(vreader_emul->slot);
}
if (vreader_emul->type_params) {
- qemu_free(vreader_emul->type_params);
+ g_free(vreader_emul->type_params);
}
- qemu_free(vreader_emul);
+ g_free(vreader_emul);
}
/*
@@ -658,9 +658,9 @@ vcard_emul_mirror_card(VReader *vreader)
/* now create the card */
card = vcard_emul_make_card(vreader, certs, cert_len, keys, cert_count);
- qemu_free(certs);
- qemu_free(cert_len);
- qemu_free(keys);
+ g_free(certs);
+ g_free(cert_len);
+ g_free(keys);
return card;
}
@@ -947,9 +947,9 @@ vcard_emul_init(const VCardEmulOptions *options)
vreader_free(vreader);
has_readers = PR_TRUE;
}
- qemu_free(certs);
- qemu_free(cert_len);
- qemu_free(keys);
+ g_free(certs);
+ g_free(cert_len);
+ g_free(keys);
}
/* if we aren't suppose to use hw, skip looking up hardware tokens */
@@ -1173,18 +1173,18 @@ vcard_emul_options(const char *args)
}
opts->vreader = vreaderOpt;
vreaderOpt = &vreaderOpt[opts->vreader_count];
- vreaderOpt->name = qemu_strndup(name, name_length);
- vreaderOpt->vname = qemu_strndup(vname, vname_length);
+ vreaderOpt->name = g_strndup(name, name_length);
+ vreaderOpt->vname = g_strndup(vname, vname_length);
vreaderOpt->card_type = type;
vreaderOpt->type_params =
- qemu_strndup(type_params, type_params_length);
+ g_strndup(type_params, type_params_length);
count = count_tokens(args, ',', ')') + 1;
vreaderOpt->cert_count = count;
- vreaderOpt->cert_name = (char **)qemu_malloc(count*sizeof(char *));
+ vreaderOpt->cert_name = (char **)g_malloc(count*sizeof(char *));
for (i = 0; i < count; i++) {
const char *cert = args;
args = strpbrk(args, ",)");
- vreaderOpt->cert_name[i] = qemu_strndup(cert, args - cert);
+ vreaderOpt->cert_name[i] = g_strndup(cert, args - cert);
args = strip(args+1);
}
if (*args == ')') {
@@ -1211,7 +1211,7 @@ vcard_emul_options(const char *args)
args = strip(args+10);
params = args;
args = find_blank(args);
- opts->hw_type_params = qemu_strndup(params, args-params);
+ opts->hw_type_params = g_strndup(params, args-params);
/* db="/data/base/path" */
} else if (strncmp(args, "db=", 3) == 0) {
const char *db;
@@ -1222,7 +1222,7 @@ vcard_emul_options(const char *args)
args++;
db = args;
args = strpbrk(args, "\"\n");
- opts->nss_db = qemu_strndup(db, args-db);
+ opts->nss_db = g_strndup(db, args-db);
if (*args != 0) {
args++;
}
diff --git a/libcacard/vreader.c b/libcacard/vreader.c
index 4a0125b0e..ec126dfa4 100644
--- a/libcacard/vreader.c
+++ b/libcacard/vreader.c
@@ -46,7 +46,7 @@ vreader_new(const char *name, VReaderEmul *private,
{
VReader *reader;
- reader = (VReader *)qemu_malloc(sizeof(VReader));
+ reader = (VReader *)g_malloc(sizeof(VReader));
qemu_mutex_init(&reader->lock);
reader->reference_count = 1;
reader->name = name ? strdup(name) : NULL;
@@ -87,12 +87,12 @@ vreader_free(VReader *reader)
vcard_free(reader->card);
}
if (reader->name) {
- qemu_free(reader->name);
+ g_free(reader->name);
}
if (reader->reader_private_free) {
reader->reader_private_free(reader->reader_private);
}
- qemu_free(reader);
+ g_free(reader);
return;
}
@@ -237,7 +237,7 @@ vreader_list_entry_new(VReader *reader)
VReaderListEntry *new_reader_list_entry;
new_reader_list_entry = (VReaderListEntry *)
- qemu_malloc(sizeof(VReaderListEntry));
+ g_malloc(sizeof(VReaderListEntry));
new_reader_list_entry->next = NULL;
new_reader_list_entry->prev = NULL;
new_reader_list_entry->reader = vreader_reference(reader);
@@ -251,7 +251,7 @@ vreader_list_entry_delete(VReaderListEntry *entry)
return;
}
vreader_free(entry->reader);
- qemu_free(entry);
+ g_free(entry);
}
@@ -260,7 +260,7 @@ vreader_list_new(void)
{
VReaderList *new_reader_list;
- new_reader_list = (VReaderList *)qemu_malloc(sizeof(VReaderList));
+ new_reader_list = (VReaderList *)g_malloc(sizeof(VReaderList));
new_reader_list->head = NULL;
new_reader_list->tail = NULL;
return new_reader_list;
@@ -278,7 +278,7 @@ vreader_list_delete(VReaderList *list)
}
list->head = NULL;
list->tail = NULL;
- qemu_free(list);
+ g_free(list);
}
diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index ce33f5a92..a7b38340d 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -488,7 +488,7 @@ main(
for (i = 0; i < cert_count; i++) {
len += strlen(cert_names[i])+1; /* 1 == comma */
}
- new_args = qemu_malloc(len);
+ new_args = g_malloc(len);
strcpy(new_args, emul_args);
strcat(new_args, SOFT_STRING);
for (i = 0; i < cert_count; i++) {