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>
diff --git a/libcacard/cac.c b/libcacard/cac.c
index f34f63a..f4b0b1b 100644
--- a/libcacard/cac.c
+++ b/libcacard/cac.c
@@ -98,7 +98,7 @@
 
     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 @@
         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 @@
                                 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 @@
     }
     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 @@
 {
     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 @@
     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 eeea849..9fd59d4 100644
--- a/libcacard/card_7816.c
+++ b/libcacard/card_7816.c
@@ -51,8 +51,8 @@
 {
     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 @@
 {
     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 @@
 {
     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 @@
     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 @@
         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 @@
         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 bb2f921..6192376 100644
--- a/libcacard/event.c
+++ b/libcacard/event.c
@@ -17,7 +17,7 @@
 {
     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 @@
     }
     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 29b4cce..b02556e 100644
--- a/libcacard/vcard.c
+++ b/libcacard/vcard.c
@@ -37,8 +37,8 @@
 {
     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 @@
         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 @@
 {
     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 @@
         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_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_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 84fc490..397485c 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -94,9 +94,9 @@
     *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 @@
 {
     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 @@
     /* 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 @@
     key->failedX509 = VCardEmulTrue;
 cleanup:
     if (bp != buf) {
-        qemu_free(bp);
+        g_free(bp);
     }
     return ret;
 }
@@ -382,7 +382,7 @@
       * 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 @@
     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 @@
 {
     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 @@
         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 @@
 
     /* 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 @@
             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 @@
             }
             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 @@
             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 @@
             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 4a0125b..ec126df 100644
--- a/libcacard/vreader.c
+++ b/libcacard/vreader.c
@@ -46,7 +46,7 @@
 {
     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 @@
         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 @@
     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 @@
         return;
     }
     vreader_free(entry->reader);
-    qemu_free(entry);
+    g_free(entry);
 }
 
 
@@ -260,7 +260,7 @@
 {
     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 @@
     }
     list->head = NULL;
     list->tail = NULL;
-    qemu_free(list);
+    g_free(list);
 }
 
 
diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index ce33f5a..a7b3834 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -488,7 +488,7 @@
         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++) {