qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2] use qemu_malloc and friends consistently


From: Jean-Christophe Dubois
Subject: [Qemu-devel] [PATCH v2] use qemu_malloc and friends consistently
Date: Fri, 29 May 2009 22:24:13 +0200
User-agent: KMail/1.11.2 (Linux/2.6.28-11-generic; KDE/4.2.2; x86_64; ; )

qemu_malloc, qemu_free and friends are not used consistently in the qemu 
source code.

This is a first attempt to use these oveloaded functions consistently all over 
the place instead of the default glibc versions.

This version avoid to use qemu_malloc in qemu-io.c if the size to allocate is 
0.

Signed-off-by: Jean-Christophe DUBOIS <address@hidden>

--- qemu.org/acl.c      Sat May 16 17:57:26 2009
+++ qemu/acl.c  Thu May 28 23:14:01 2009
@@ -104,8 +104,8 @@
     acl->defaultDeny = 1;
     TAILQ_FOREACH(entry, &acl->entries, next) {
         TAILQ_REMOVE(&acl->entries, entry, next);
-        free(entry->match);
-        free(entry);
+        qemu_free(entry->match);
+        qemu_free(entry);
     }
     acl->nentries = 0;
 }
--- qemu.org/audio/paaudio.c    Sat May 16 17:57:26 2009
+++ qemu/audio/paaudio.c        Thu May 28 23:14:01 2009
@@ -340,7 +340,7 @@
     return 0;
 
  fail3:
-    free (pa->pcm_buf);
+    qemu_free (pa->pcm_buf);
     pa->pcm_buf = NULL;
  fail2:
     pa_simple_free (pa->s);
@@ -394,7 +394,7 @@
     return 0;
 
  fail3:
-    free (pa->pcm_buf);
+    qemu_free (pa->pcm_buf);
     pa->pcm_buf = NULL;
  fail2:
     pa_simple_free (pa->s);
--- qemu.org/block/cloop.c      Sat May 16 17:57:26 2009
+++ qemu/block/cloop.c  Thu May 28 23:14:01 2009
@@ -148,9 +148,9 @@
     BDRVCloopState *s = bs->opaque;
     close(s->fd);
     if(s->n_blocks>0)
-       free(s->offsets);
-    free(s->compressed_block);
-    free(s->uncompressed_block);
+       qemu_free(s->offsets);
+    qemu_free(s->compressed_block);
+    qemu_free(s->uncompressed_block);
     inflateEnd(&s->zstream);
 }
 
--- qemu.org/block/dmg.c        Sat May 16 17:57:26 2009
+++ qemu/block/dmg.c    Thu May 28 23:14:01 2009
@@ -273,14 +273,14 @@
     BDRVDMGState *s = bs->opaque;
     close(s->fd);
     if(s->n_chunks>0) {
-       free(s->types);
-       free(s->offsets);
-       free(s->lengths);
-       free(s->sectors);
-       free(s->sectorcounts);
+       qemu_free(s->types);
+       qemu_free(s->offsets);
+       qemu_free(s->lengths);
+       qemu_free(s->sectors);
+       qemu_free(s->sectorcounts);
     }
-    free(s->compressed_chunk);
-    free(s->uncompressed_chunk);
+    qemu_free(s->compressed_chunk);
+    qemu_free(s->uncompressed_chunk);
     inflateEnd(&s->zstream);
 }
 
--- qemu.org/block/vvfat.c      Sat May 16 17:57:26 2009
+++ qemu/block/vvfat.c  Thu May 28 23:14:01 2009
@@ -87,7 +87,7 @@
 static inline void array_free(array_t* array)
 {
     if(array->pointer)
-        free(array->pointer);
+        qemu_free(array->pointer);
     array->size=array->next=0;
 }
 
@@ -169,7 +169,7 @@
 
     memcpy(to,buf,is*count);
 
-    free(buf);
+    qemu_free(buf);
 
     return 0;
 }
@@ -732,7 +732,7 @@
        snprintf(buffer,length,"%s/%s",dirname,entry->d_name);
 
        if(stat(buffer,&st)<0) {
-           free(buffer);
+           qemu_free(buffer);
             continue;
        }
 
@@ -755,7 +755,7 @@
            direntry->begin=0; /* do that later */
         if (st.st_size > 0x7fffffff) {
            fprintf(stderr, "File %s is larger than 2GB\n", buffer);
-           free(buffer);
+           qemu_free(buffer);
            return -2;
         }
        direntry->size=cpu_to_le32(S_ISDIR(st.st_mode)?0:st.st_size);
@@ -882,7 +882,7 @@
     mapping->dir_index = 0;
     mapping->info.dir.parent_mapping_index = -1;
     mapping->first_mapping_index = -1;
-    mapping->path = strdup(dirname);
+    mapping->path = qemu_strdup(dirname);
     i = strlen(mapping->path);
     if (i > 0 && mapping->path[i - 1] == '/')
        mapping->path[i - 1] = '\0';
@@ -1369,7 +1369,7 @@
        assert(commit->path || commit->action == ACTION_WRITEOUT);
        if (commit->action != ACTION_WRITEOUT) {
            assert(commit->path);
-           free(commit->path);
+           qemu_free(commit->path);
        } else
            assert(commit->path == NULL);
     }
@@ -1632,10 +1632,10 @@
 
            /* rename */
            if (strcmp(basename, basename2))
-               schedule_rename(s, cluster_num, strdup(path));
+               schedule_rename(s, cluster_num, qemu_strdup(path));
        } else if (is_file(direntry))
            /* new file */
-           schedule_new_file(s, strdup(path), cluster_num);
+           schedule_new_file(s, qemu_strdup(path), cluster_num);
        else {
            assert(0);
            return 0;
@@ -1752,10 +1752,10 @@
        mapping->mode &= ~MODE_DELETED;
 
        if (strcmp(basename, basename2))
-           schedule_rename(s, cluster_num, strdup(path));
+           schedule_rename(s, cluster_num, qemu_strdup(path));
     } else
        /* new directory */
-       schedule_mkdir(s, cluster_num, strdup(path));
+       schedule_mkdir(s, cluster_num, qemu_strdup(path));
 
     lfn_init(&lfn);
     do {
@@ -1776,7 +1776,7 @@
        if (subret) {
            fprintf(stderr, "Error fetching direntries\n");
        fail:
-           free(cluster);
+           qemu_free(cluster);
            return 0;
        }
 
@@ -1844,7 +1844,7 @@
        cluster_num = modified_fat_get(s, cluster_num);
     } while(!fat_eof(s, cluster_num));
 
-    free(cluster);
+    qemu_free(cluster);
     return ret;
 }
 
@@ -1990,7 +1990,7 @@
 
     /* free mapping */
     if (mapping->first_mapping_index < 0)
-       free(mapping->path);
+       qemu_free(mapping->path);
 
     /* remove from s->mapping */
     array_remove(&(s->mapping), mapping_index);
@@ -2390,7 +2390,7 @@
                }
            }
 
-           free(old_path);
+           qemu_free(old_path);
            array_remove(&(s->commits), i);
            continue;
        } else if (commit->action == ACTION_MKDIR) {
@@ -2758,7 +2758,7 @@
 static void write_target_close(BlockDriverState *bs) {
     BDRVVVFATState* s = bs->opaque;
     bdrv_delete(s->qcow);
-    free(s->qcow_filename);
+    qemu_free(s->qcow_filename);
 }
 
 static BlockDriver vvfat_write_target = {
@@ -2771,7 +2771,7 @@
 static int enable_write_target(BDRVVVFATState *s)
 {
     int size = sector2cluster(s, s->sector_count);
-    s->used_clusters = calloc(size, 1);
+    s->used_clusters = qemu_mallocz(size);
 
     array_init(&(s->commits), sizeof(commit_t));
 
@@ -2788,7 +2788,7 @@
     unlink(s->qcow_filename);
 #endif
 
-    s->bs->backing_hd = calloc(sizeof(BlockDriverState), 1);
+    s->bs->backing_hd = qemu_mallocz(sizeof(BlockDriverState));
     s->bs->backing_hd->drv = &vvfat_write_target;
     s->bs->backing_hd->opaque = s;
 
@@ -2804,7 +2804,7 @@
     array_free(&(s->directory));
     array_free(&(s->mapping));
     if(s->cluster_buffer)
-        free(s->cluster_buffer);
+        qemu_free(s->cluster_buffer);
 }
 
 static BlockDriver bdrv_vvfat = {
--- qemu.org/bsd-user/main.c    Sat May 16 17:57:26 2009
+++ qemu/bsd-user/main.c        Thu May 28 23:14:01 2009
@@ -822,7 +822,7 @@
     while (*(wrk++))
         environ_count++;
 
-    target_environ = malloc((environ_count + 1) * sizeof(char *));
+    target_environ = qemu_malloc((environ_count + 1) * sizeof(char *));
     if (!target_environ)
         abort();
     for (wrk = environ, dst = target_environ; *wrk; wrk++) {
@@ -838,10 +838,10 @@
     }
 
     for (wrk = target_environ; *wrk; wrk++) {
-        free(*wrk);
+        qemu_free(*wrk);
     }
 
-    free(target_environ);
+    qemu_free(target_environ);
 
     if (qemu_log_enabled()) {
         log_page_dump();
--- qemu.org/bsd-user/path.c    Sat May 16 17:57:26 2009
+++ qemu/bsd-user/path.c        Thu May 28 23:14:01 2009
@@ -45,8 +45,8 @@
                                   struct pathelem *parent,
                                   const char *name)
 {
-    struct pathelem *new = malloc(sizeof(*new));
-    new->name = strdup(name);
+    struct pathelem *new = qemu_malloc(sizeof(*new));
+    new->name = qemu_strdup(name);
     asprintf(&new->pathname, "%s/%s", root, name);
     new->num_entries = 0;
     return new;
@@ -75,7 +75,7 @@
 {
     root->num_entries++;
 
-    root = realloc(root, sizeof(*root)
+    root = qemu_realloc(root, sizeof(*root)
                    + sizeof(root->entries[0])*root->num_entries);
 
     root->entries[root->num_entries-1] = new_entry(root->pathname, root, 
name);
@@ -137,14 +137,14 @@
         pstrcpy(pref_buf, sizeof(pref_buf), cwd);
         pstrcat(pref_buf, pref_buf_len, "/");
         pstrcat(pref_buf, pref_buf_len, prefix);
-        free(cwd);
+        qemu_free(cwd);
     } else
         pstrcpy(pref_buf, sizeof(pref_buf), prefix + 1);
 
     base = new_entry("", NULL, pref_buf);
     base = add_dir_maybe(base);
     if (base->num_entries == 0) {
-        free (base);
+        qemu_free (base);
         base = NULL;
     } else {
         set_parents(base, base);
--- qemu.org/hw/baum.c  Sat May 16 17:57:26 2009
+++ qemu/hw/baum.c      Thu May 28 23:14:01 2009
@@ -558,7 +558,7 @@
     if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != 
EINTR)) {
         brlapi_perror("baum: brlapi_readKey");
         brlapi__closeConnection(baum->brlapi);
-        free(baum->brlapi);
+        qemu_free(baum->brlapi);
         baum->brlapi = NULL;
     }
 }
@@ -621,9 +621,9 @@
     qemu_free_timer(baum->cellCount_timer);
     brlapi__closeConnection(handle);
 fail_handle:
-    free(handle);
-    free(chr);
-    free(baum);
+    qemu_free(handle);
+    qemu_free(chr);
+    qemu_free(baum);
     return NULL;
 }
 
--- qemu.org/hw/bt-l2cap.c      Sat May 16 17:57:26 2009
+++ qemu/hw/bt-l2cap.c  Thu May 28 23:14:01 2009
@@ -1220,7 +1220,7 @@
     for (cid = L2CAP_CID_ALLOC; cid < L2CAP_CID_MAX; cid ++)
         if (l2cap->cid[cid]) {
             l2cap->cid[cid]->params.close(l2cap->cid[cid]->params.opaque);
-            free(l2cap->cid[cid]);
+            qemu_free(l2cap->cid[cid]);
         }
 
     if (l2cap->role)
--- qemu.org/hw/nseries.c       Sat May 16 17:57:26 2009
+++ qemu/hw/nseries.c   Thu May 28 23:14:02 2009
@@ -711,7 +711,7 @@
     fb_blank = memset(qemu_malloc(800 * 480 * 2), 0xff, 800 * 480 * 2);
     /* Display Memory Data Port */
     chip->block(chip->opaque, 1, fb_blank, 800 * 480 * 2, 800);
-    free(fb_blank);
+    qemu_free(fb_blank);
 }
 
 static void n8x0_dss_setup(struct n800_s *s)
--- qemu.org/hw/ppc440_bamboo.c Sat May 16 17:57:26 2009
+++ qemu/hw/ppc440_bamboo.c     Thu May 28 23:14:02 2009
@@ -45,7 +45,7 @@
     snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
 
     fdt = load_device_tree(path, &fdt_size);
-    free(path);
+    qemu_free(path);
     if (fdt == NULL)
         goto out;
 
--- qemu.org/hw/scsi-generic.c  Sat May 16 17:57:26 2009
+++ qemu/hw/scsi-generic.c      Thu May 28 23:14:02 2009
@@ -564,7 +564,7 @@
 
     if (len == 0) {
         if (r->buf != NULL)
-            free(r->buf);
+            qemu_free(r->buf);
         r->buflen = 0;
         r->buf = NULL;
         ret = execute_command(s->bdrv, r, SG_DXFER_NONE, 
scsi_command_complete);
@@ -577,7 +577,7 @@
 
     if (r->buflen != len) {
         if (r->buf != NULL)
-            free(r->buf);
+            qemu_free(r->buf);
         r->buf = qemu_malloc(len);
         r->buflen = len;
     }
--- qemu.org/linux-user/main.c  Sat May 16 17:57:26 2009
+++ qemu/linux-user/main.c      Thu May 28 23:14:02 2009
@@ -2464,7 +2464,7 @@
      * Prepare copy of argv vector for target.
      */
     target_argc = argc - optind;
-    target_argv = calloc(target_argc + 1, sizeof (char *));
+    target_argv = qemu_mallocz((target_argc + 1) * sizeof (char *));
     if (target_argv == NULL) {
        (void) fprintf(stderr, "Unable to allocate memory for target_argv\n");
        exit(1);
@@ -2489,15 +2489,15 @@
     }
 
     for (i = 0; i < target_argc; i++) {
-        free(target_argv[i]);
+        qemu_free(target_argv[i]);
     }
-    free(target_argv);
+    qemu_free(target_argv);
 
     for (wrk = target_environ; *wrk; wrk++) {
-        free(*wrk);
+        qemu_free(*wrk);
     }
 
-    free(target_environ);
+    qemu_free(target_environ);
 
     if (qemu_log_enabled()) {
         log_page_dump();
--- qemu.org/linux-user/syscall.c       Sat May 16 17:57:26 2009
+++ qemu/linux-user/syscall.c   Thu May 28 23:14:02 2009
@@ -2094,7 +2094,7 @@
 
     nsems = semid_ds.sem_nsems;
 
-    *host_array = malloc(nsems*sizeof(unsigned short));
+    *host_array = qemu_malloc(nsems*sizeof(unsigned short));
     array = lock_user(VERIFY_READ, target_addr,
                       nsems*sizeof(unsigned short), 1);
     if (!array)
@@ -2133,7 +2133,7 @@
     for(i=0; i<nsems; i++) {
         __put_user((*host_array)[i], &array[i]);
     }
-    free(*host_array);
+    qemu_free(*host_array);
     unlock_user(array, target_addr, 1);
 
     return 0;
@@ -2379,11 +2379,11 @@
 
     if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0))
         return -TARGET_EFAULT;
-    host_mb = malloc(msgsz+sizeof(long));
+    host_mb = qemu_malloc(msgsz+sizeof(long));
     host_mb->mtype = (abi_long) tswapl(target_mb->mtype);
     memcpy(host_mb->mtext, target_mb->mtext, msgsz);
     ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
-    free(host_mb);
+    qemu_free(host_mb);
     unlock_user_struct(target_mb, msgp, 0);
 
     return ret;
@@ -2401,7 +2401,7 @@
     if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0))
         return -TARGET_EFAULT;
 
-    host_mb = malloc(msgsz+sizeof(long));
+    host_mb = qemu_malloc(msgsz+sizeof(long));
     ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapl(msgtyp), msgflg));
 
     if (ret > 0) {
@@ -2416,7 +2416,7 @@
     }
 
     target_mb->mtype = tswapl(host_mb->mtype);
-    free(host_mb);
+    qemu_free(host_mb);
 
 end:
     if (target_mb)
@@ -5428,7 +5428,7 @@
             struct linux_dirent *dirp;
             abi_long count = arg3;
 
-           dirp = malloc(count);
+           dirp = qemu_malloc(count);
            if (!dirp) {
                 ret = -TARGET_ENOMEM;
                 goto fail;
@@ -5466,7 +5466,7 @@
                ret = count1;
                 unlock_user(target_dirp, arg2, ret);
             }
-           free(dirp);
+           qemu_free(dirp);
         }
 #else
         {
--- qemu.org/migration.c        Sat May 16 17:57:27 2009
+++ qemu/migration.c    Thu May 28 23:14:02 2009
@@ -266,7 +266,7 @@
         s->state = MIG_STATE_CANCELLED;
         migrate_fd_cleanup(s);
     }
-    free(s);
+    qemu_free(s);
 }
 
 void migrate_fd_wait_for_unfreeze(void *opaque)
--- qemu.org/net.c      Sat May 16 17:57:27 2009
+++ qemu/net.c  Thu May 28 23:14:02 2009
@@ -214,7 +214,7 @@
                         struct sockaddr_in *saddr,
                         const char *input_str)
 {
-    char *str = strdup(input_str);
+    char *str = qemu_strdup(input_str);
     char *host_str = str;
     char *src_str;
     const char *src_str2;
@@ -243,11 +243,11 @@
     if (parse_host_port(saddr, src_str2) < 0)
         goto fail;
 
-    free(str);
+    qemu_free(str);
     return(0);
 
 fail:
-    free(str);
+    qemu_free(str);
     return -1;
 }
 
@@ -326,7 +326,7 @@
 
     snprintf(buf, sizeof(buf), "%s.%d", model, id);
 
-    return strdup(buf);
+    return qemu_strdup(buf);
 }
 
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
@@ -339,9 +339,9 @@
 {
     VLANClientState *vc, **pvc;
     vc = qemu_mallocz(sizeof(VLANClientState));
-    vc->model = strdup(model);
+    vc->model = qemu_strdup(model);
     if (name)
-        vc->name = strdup(name);
+        vc->name = qemu_strdup(name);
     else
         vc->name = assign_name(vc, model);
     vc->fd_read = fd_read;
@@ -368,8 +368,8 @@
             if (vc->cleanup) {
                 vc->cleanup(vc);
             }
-            free(vc->name);
-            free(vc->model);
+            qemu_free(vc->name);
+            qemu_free(vc->model);
             qemu_free(vc);
             break;
         } else
@@ -1147,7 +1147,7 @@
     s = qemu_mallocz(sizeof(VDEState));
     s->vde = vde_open(init_sock, (char *)"QEMU", &args);
     if (!s->vde){
-        free(s);
+        qemu_free(s);
         return -1;
     }
     s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu,
@@ -1515,8 +1515,8 @@
         return -1;
     }
     s->vlan = vlan;
-    s->model = strdup(model);
-    s->name = name ? strdup(name) : NULL;
+    s->model = qemu_strdup(model);
+    s->name = name ? qemu_strdup(name) : NULL;
     s->fd = fd;
     qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
     return 0;
@@ -1746,7 +1746,7 @@
     int i, exit_status = 0;
 
     if (!nd->model)
-        nd->model = strdup(default_model);
+        nd->model = qemu_strdup(default_model);
 
     if (strcmp(nd->model, "?") != 0) {
         for (i = 0 ; models[i]; i++)
@@ -1781,7 +1781,7 @@
     vlan = qemu_find_vlan(vlan_id);
 
     if (get_param_value(buf, sizeof(buf), "name", p)) {
-        name = strdup(buf);
+        name = qemu_strdup(buf);
     }
     if (!strcmp(device, "nic")) {
         static const char * const nic_params[] = {
@@ -1818,7 +1818,7 @@
             }
         }
         if (get_param_value(buf, sizeof(buf), "model", p)) {
-            nd->model = strdup(buf);
+            nd->model = qemu_strdup(buf);
         }
         nd->vlan = vlan;
         nd->name = name;
@@ -1854,7 +1854,7 @@
             slirp_restrict = (buf[0] == 'y') ? 1 : 0;
         }
         if (get_param_value(buf, sizeof(buf), "ip", p)) {
-            slirp_ip = strdup(buf);
+            slirp_ip = qemu_strdup(buf);
         }
         vlan->nb_host_devs++;
         ret = net_slirp_init(vlan, device, name);
@@ -1870,7 +1870,7 @@
             ret = -1;
             goto out;
         }
-        vmc = malloc(sizeof(struct VMChannel));
+        vmc = qemu_malloc(sizeof(struct VMChannel));
         snprintf(name, 20, "vmchannel%ld", port);
         vmc->hd = qemu_chr_open(name, devname, NULL);
         if (!vmc->hd) {
@@ -2047,7 +2047,7 @@
     }
 out:
     if (name)
-        free(name);
+        qemu_free(name);
     return ret;
 }
 
@@ -2056,7 +2056,7 @@
     nd->vlan->nb_guest_devs--;
     nb_nics--;
     nd->used = 0;
-    free((void *)nd->model);
+    qemu_free((void *)nd->model);
 }
 
 static int net_host_check_device(const char *device)
--- qemu.org/qemu-char.c        Sat May 16 17:57:27 2009
+++ qemu/qemu-char.c    Thu May 28 23:14:02 2009
@@ -1553,8 +1553,8 @@
     chr->chr_close = win_chr_close;
 
     if (win_chr_init(chr, filename) < 0) {
-        free(s);
-        free(chr);
+        qemu_free(s);
+        qemu_free(chr);
         return NULL;
     }
     qemu_chr_reset(chr);
@@ -1652,8 +1652,8 @@
     chr->chr_close = win_chr_close;
 
     if (win_chr_pipe_init(chr, filename) < 0) {
-        free(s);
-        free(chr);
+        qemu_free(s);
+        qemu_free(chr);
         return NULL;
     }
     qemu_chr_reset(chr);
@@ -1808,9 +1808,9 @@
 
 return_err:
     if (chr)
-        free(chr);
+        qemu_free(chr);
     if (s)
-        free(s);
+        qemu_free(s);
     if (fd >= 0)
         closesocket(fd);
     return NULL;
--- qemu.org/qemu-img.c Sat May 16 17:57:27 2009
+++ qemu/qemu-img.c     Thu May 28 23:14:02 2009
@@ -696,7 +696,7 @@
     bdrv_delete(out_bs);
     for (bs_i = 0; bs_i < bs_n; bs_i++)
         bdrv_delete(bs[bs_i]);
-    free(bs);
+    qemu_free(bs);
     return 0;
 }
 
--- qemu.org/qemu-io.c  Sat May 16 17:57:27 2009
+++ qemu/qemu-io.c      Fri May 29 19:45:51 2009
@@ -310,15 +310,15 @@
                return 0;
        }
 
-       if (Pflag) {
-               void* cmp_buf = malloc(pattern_count);
+       if (Pflag && pattern_count) {
+               void* cmp_buf = qemu_malloc(pattern_count);
                memset(cmp_buf, pattern, pattern_count);
                if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {
                        printf("Pattern verification failed at offset %lld, "
                                "%d bytes\n",
                                (long long) offset + pattern_offset, 
pattern_count);
                }
-               free(cmp_buf);
+               qemu_free(cmp_buf);
        }
 
        if (qflag)
@@ -464,15 +464,15 @@
                return 0;
        }
 
-       if (Pflag) {
-               void* cmp_buf = malloc(count);
+       if (Pflag && count) {
+               void* cmp_buf = qemu_malloc(count);
                memset(cmp_buf, pattern, count);
                if (memcmp(buf, cmp_buf, count)) {
                        printf("Pattern verification failed at offset %lld, "
                                "%d bytes\n",
                                (long long) offset, count);
                }
-               free(cmp_buf);
+               qemu_free(cmp_buf);
        }
 
        if (qflag)
--- qemu.org/readline.c Sat May 16 17:57:27 2009
+++ qemu/readline.c     Thu May 28 23:14:02 2009
@@ -246,7 +246,7 @@
     }
     if (idx == READLINE_MAX_CMDS) {
        /* Need to get one free slot */
-       free(rs->history[0]);
+       qemu_free(rs->history[0]);
        memcpy(rs->history, &rs->history[1],
               (READLINE_MAX_CMDS - 1) * sizeof(char *));
        rs->history[READLINE_MAX_CMDS - 1] = NULL;
--- qemu.org/slirp/socket.c     Sat May 16 17:57:27 2009
+++ qemu/slirp/socket.c Thu May 28 23:14:02 2009
@@ -53,7 +53,7 @@
 {
   struct socket *so;
 
-  so = (struct socket *)malloc(sizeof(struct socket));
+  so = (struct socket *)qemu_malloc(sizeof(struct socket));
   if(so) {
     memset(so, 0, sizeof(struct socket));
     so->so_state = SS_NOFDREF;
@@ -82,7 +82,7 @@
   if(so->so_next && so->so_prev)
     remque(so);  /* crashes if so is not in a queue */
 
-  free(so);
+  qemu_free(so);
 }
 
 size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)
@@ -601,13 +601,13 @@
        DEBUG_ARG("flags = %x", flags);
 
        if ((so = socreate()) == NULL) {
-         /* free(so);      Not sofree() ??? free(NULL) == NOP */
+         /* qemu_free(so);      Not sofree() ??? qemu_free(NULL) == NOP */
          return NULL;
        }
 
        /* Don't tcp_attach... we don't need so_snd nor so_rcv */
        if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {
-               free(so);
+               qemu_free(so);
                return NULL;
        }
        insque(so,&tcb);
--- qemu.org/target-arm/helper.c        Sat May 16 17:57:27 2009
+++ qemu/target-arm/helper.c    Thu May 28 23:14:02 2009
@@ -330,7 +330,7 @@
 
 void cpu_arm_close(CPUARMState *env)
 {
-    free(env);
+    qemu_free(env);
 }
 
 uint32_t cpsr_read(CPUARMState *env)
@@ -466,7 +466,7 @@
 
 static void allocate_mmon_state(CPUState *env)
 {
-    env->mmon_entry = malloc(sizeof (mmon_state));
+    env->mmon_entry = qemu_malloc(sizeof (mmon_state));
     memset (env->mmon_entry, 0, sizeof (mmon_state));
     env->mmon_entry->cpu_env = env;
     mmon_head = env->mmon_entry;
--- qemu.org/target-i386/helper.c       Sat May 16 17:57:27 2009
+++ qemu/target-i386/helper.c   Thu May 28 23:14:02 2009
@@ -397,11 +397,11 @@
     x86_cpu_def->ext_features &= ~minus_ext_features;
     x86_cpu_def->ext2_features &= ~minus_ext2_features;
     x86_cpu_def->ext3_features &= ~minus_ext3_features;
-    free(s);
+    qemu_free(s);
     return 0;
 
 error:
-    free(s);
+    qemu_free(s);
     return -1;
 }
 
--- qemu.org/target-i386/kvm.c  Sat May 16 17:57:27 2009
+++ qemu/target-i386/kvm.c      Thu May 28 23:14:02 2009
@@ -224,7 +224,7 @@
             }
         }
 
-        free(kvm_msr_list);
+        qemu_free(kvm_msr_list);
     }
 
     if (has_msr_star == 1)
--- qemu.org/target-ppc/kvm_ppc.c       Sat May 16 17:57:27 2009
+++ qemu/target-ppc/kvm_ppc.c   Thu May 28 23:14:02 2009
@@ -51,7 +51,7 @@
 close:
     fclose(f);
 free:
-    free(path);
+    qemu_free(path);
 out:
     return ret;
 }
--- qemu.org/target-sparc/helper.c      Sat May 16 17:57:27 2009
+++ qemu/target-sparc/helper.c  Thu May 28 23:14:02 2009
@@ -706,8 +706,8 @@
 
 static void cpu_sparc_close(CPUSPARCState *env)
 {
-    free(env->def);
-    free(env);
+    qemu_free(env->def);
+    qemu_free(env);
 }
 
 CPUSPARCState *cpu_sparc_init(const char *cpu_model)
@@ -1333,11 +1333,11 @@
 #ifdef DEBUG_FEATURES
     print_features(stderr, fprintf, cpu_def->features, NULL);
 #endif
-    free(s);
+    qemu_free(s);
     return 0;
 
  error:
-    free(s);
+    qemu_free(s);
     return -1;
 }
 
--- qemu.org/tcg/tcg.c  Sat May 16 17:57:27 2009
+++ qemu/tcg/tcg.c      Thu May 28 23:14:02 2009
@@ -341,7 +341,7 @@
 #endif
         pstrcpy(buf, sizeof(buf), name);
         pstrcat(buf, sizeof(buf), "_0");
-        ts->name = strdup(buf);
+        ts->name = qemu_strdup(buf);
         ts++;
 
         ts->base_type = type;
@@ -356,7 +356,7 @@
 #endif
         pstrcpy(buf, sizeof(buf), name);
         pstrcat(buf, sizeof(buf), "_1");
-        ts->name = strdup(buf);
+        ts->name = qemu_strdup(buf);
 
         s->nb_globals += 2;
     } else
@@ -531,7 +531,7 @@
         } else {
             n *= 2;
         }
-        s->helpers = realloc(s->helpers, n * sizeof(TCGHelperInfo));
+        s->helpers = qemu_realloc(s->helpers, n * sizeof(TCGHelperInfo));
         s->allocated_helpers = n;
     }
     s->helpers[s->nb_helpers].func = (tcg_target_ulong)func;
--- qemu.org/vl.c       Sat May 16 17:57:27 2009
+++ qemu/vl.c   Thu May 28 23:14:03 2009
@@ -1071,7 +1071,7 @@
         exit(0);
     }
 
-    arg = strdup(opt);
+    arg = qemu_strdup(opt);
 
     /* Reorder the array */
     name = strtok(arg, ",");
@@ -1100,7 +1100,7 @@
         name = strtok(NULL, ",");
     }
 
-    free(arg);
+    qemu_free(arg);
 
     if (cur) {
         /* Disable remaining timers */
@@ -5711,7 +5716,7 @@
                         fprintf(stderr, "Too many option ROMs\n");
                         exit(1);
                     }
-                    option_rom[nb_option_roms] = strdup(buf);
+                    option_rom[nb_option_roms] = qemu_strdup(buf);
                     nb_option_roms++;
                     netroms++;
                 }
--- qemu.org/vnc-auth-sasl.c    Sat May 16 17:57:27 2009
+++ qemu/vnc-auth-sasl.c        Thu May 28 23:14:03 2009
@@ -34,8 +34,8 @@
         vs->sasl.runSSF = vs->sasl.waitWriteSSF = vs->sasl.wantSSF = 0;
         vs->sasl.encodedLength = vs->sasl.encodedOffset = 0;
         vs->sasl.encoded = NULL;
-        free(vs->sasl.username);
-        free(vs->sasl.mechlist);
+        qemu_free(vs->sasl.username);
+        qemu_free(vs->sasl.mechlist);
         vs->sasl.username = vs->sasl.mechlist = NULL;
         sasl_dispose(&vs->sasl.conn);
         vs->sasl.conn = NULL;
@@ -429,7 +429,7 @@
 
 static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, 
size_t len)
 {
-    char *mechname = malloc(len + 1);
+    char *mechname = qemu_malloc(len + 1);
     if (!mechname) {
         VNC_DEBUG("Out of memory reading mechname\n");
         vnc_client_error(vs);
@@ -462,7 +462,7 @@
         }
     }
 
-    free(vs->sasl.mechlist);
+    qemu_free(vs->sasl.mechlist);
     vs->sasl.mechlist = mechname;
 
     VNC_DEBUG("Validated mechname '%s'\n", mechname);
@@ -510,7 +510,7 @@
         goto authabort;
 
     if (!(remoteAddr = vnc_socket_remote_addr("%s;%s", vs->csock))) {
-        free(localAddr);
+        qemu_free(localAddr);
         goto authabort;
     }
 
@@ -522,8 +522,8 @@
                           NULL, /* Callbacks, not needed */
                           SASL_SUCCESS_DATA,
                           &vs->sasl.conn);
-    free(localAddr);
-    free(remoteAddr);
+    qemu_free(localAddr);
+    qemu_free(remoteAddr);
     localAddr = remoteAddr = NULL;
 
     if (err != SASL_OK) {
@@ -612,7 +612,7 @@
     }
     VNC_DEBUG("Available mechanisms for client: '%s'\n", mechlist);
 
-    if (!(vs->sasl.mechlist = strdup(mechlist))) {
+    if (!(vs->sasl.mechlist = qemu_strdup(mechlist))) {
         VNC_DEBUG("Out of memory");
         sasl_dispose(&vs->sasl.conn);
         vs->sasl.conn = NULL;
--- qemu.org/vnc-tls.c  Sat May 16 17:57:27 2009
+++ qemu/vnc-tls.c      Thu May 28 23:14:03 2009
@@ -382,7 +382,7 @@
         vs->tls.session = NULL;
     }
     vs->tls.wiremode = VNC_WIREMODE_CLEAR;
-    free(vs->tls.dname);
+    qemu_free(vs->tls.dname);
 }
 
 
--- qemu.org/vnc.c      Sat May 16 17:57:27 2009
+++ qemu/vnc.c  Thu May 28 23:14:03 2009
@@ -159,7 +159,7 @@
 
     monitor_printf(mon, "Client:\n");
     monitor_printf(mon, "%s", clientAddr);
-    free(clientAddr);
+    qemu_free(clientAddr);
 
 #ifdef CONFIG_VNC_TLS
     if (client->tls.session &&
@@ -190,7 +190,7 @@
 
         monitor_printf(mon, "Server:\n");
         monitor_printf(mon, "%s", serverAddr);
-        free(serverAddr);
+        qemu_free(serverAddr);
         monitor_printf(mon, "        auth: %s\n", 
vnc_auth_name(vnc_display));
 
         if (vnc_display->clients) {
@@ -533,8 +533,8 @@
                                   last_bg, last_fg, &has_bg, &has_fg);
         }
     }
-    free(last_fg);
-    free(last_bg);
+    qemu_free(last_fg);
+    qemu_free(last_bg);
 
 }
 
@@ -2123,7 +2123,7 @@
     if (strcmp(display, "none") == 0)
         return 0;
 
-    if (!(vs->display = strdup(display)))
+    if (!(vs->display = qemu_strdup(display)))
         return -1;
 
     options = display;
@@ -2275,7 +2275,7 @@
     if ((saslErr = sasl_server_init(NULL, "qemu")) != SASL_OK) {
         fprintf(stderr, "Failed to initialize SASL auth %s",
                 sasl_errstring(saslErr, NULL, NULL));
-        free(vs->display);
+        qemu_free(vs->display);
         vs->display = NULL;
         return -1;
     }
@@ -2288,7 +2288,7 @@
         else
             vs->lsock = inet_connect(display, SOCK_STREAM);
         if (-1 == vs->lsock) {
-            free(vs->display);
+            qemu_free(vs->display);
             vs->display = NULL;
             return -1;
         } else {
@@ -2309,10 +2309,10 @@
             vs->lsock = inet_listen(display, dpy, 256, SOCK_STREAM, 5900);
         }
         if (-1 == vs->lsock) {
-            free(dpy);
+            qemu_free(dpy);
             return -1;
         } else {
-            free(vs->display);
+            qemu_free(vs->display);
             vs->display = dpy;
         }
     }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]