qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 2/5] Convert use of ptr = g_malloc(sizeof(*ptr)) to


From: Stuart Brady
Subject: [Qemu-devel] [PATCH 2/5] Convert use of ptr = g_malloc(sizeof(*ptr)) to g_new()
Date: Thu, 20 Oct 2011 09:03:37 +0100

Convert calls to g_malloc() and g_malloc0() to g_new() and g_new0()
respectively, in cases where the size passed to g_malloc() is specified
as that of the type referenced by the pointer to which the result is
assigned.

This was achieved using Coccinelle with the following semantic patch:

@@ type T; T *E; @@
-E = g_malloc(sizeof(*E))
+E = g_new(T, 1)

@@ type T; T *E; @@
-E = g_malloc0(sizeof(*E))
+E = g_new0(T, 1)

@@ type T; T *E; expression N; @@
-E = g_malloc(sizeof(*E) * N)
+E = g_new(T, N)

@@ type T; T *E; expression N; @@
-E = g_malloc0(sizeof(*E) * N)
+E = g_new0(T, N)

Signed-off-by: Stuart Brady <address@hidden>
---
 acl.c                       |    6 +++---
 arch_init.c                 |    2 +-
 audio/wavcapture.c          |    2 +-
 block.c                     |    2 +-
 block/blkdebug.c            |    2 +-
 block/qcow2-cache.c         |    2 +-
 block/qed-cluster.c         |    2 +-
 block/qed-l2-cache.c        |    2 +-
 block/rbd.c                 |    2 +-
 block/sheepdog.c            |    4 ++--
 blockdev.c                  |    2 +-
 buffered_file.c             |    2 +-
 coroutine-gthread.c         |    4 ++--
 coroutine-ucontext.c        |    4 ++--
 coroutine-win32.c           |    2 +-
 error.c                     |    4 ++--
 exec.c                      |   12 ++++++------
 fsdev/qemu-fsdev.c          |    2 +-
 gdbstub.c                   |    2 +-
 hw/9pfs/virtio-9p.c         |    4 ++--
 hw/bt-hid.c                 |    2 +-
 hw/bt-l2cap.c               |    4 ++--
 hw/bt-sdp.c                 |   12 +++++-------
 hw/cirrus_vga.c             |    2 +-
 hw/etraxfs_dma.c            |    2 +-
 hw/grlib_irqmp.c            |    2 +-
 hw/isa_mmio.c               |    2 +-
 hw/loader.c                 |    4 ++--
 hw/msix.c                   |    3 +--
 hw/omap_l4.c                |    2 +-
 hw/omap_synctimer.c         |    2 +-
 hw/pc.c                     |   12 ++++++------
 hw/pc_piix.c                |    2 +-
 hw/pci.c                    |    4 ++--
 hw/pcie_port.c              |    2 +-
 hw/ppc405_boards.c          |    4 ++--
 hw/ppc440.c                 |    3 +--
 hw/qdev-properties.c        |    2 +-
 hw/spapr.c                  |    2 +-
 hw/sysbus.c                 |    2 +-
 hw/usb-desc.c               |    2 +-
 hw/usb-ehci.c               |    2 +-
 hw/usb-musb.c               |    2 +-
 hw/vga-isa-mm.c             |    6 +++---
 hw/vga.c                    |    4 ++--
 hw/vhost.c                  |    2 +-
 hw/vhost_net.c              |    2 +-
 hw/virtio-blk.c             |    2 +-
 hw/xen_devconfig.c          |    2 +-
 hw/xen_disk.c               |    2 +-
 hw/xics.c                   |    4 ++--
 hw/xtensa_lx60.c            |    8 ++++----
 hw/xtensa_sim.c             |    4 ++--
 linux-aio.c                 |    2 +-
 linux-user/elfload.c        |    6 +++---
 memory.c                    |    2 +-
 migration-exec.c            |    2 +-
 migration-fd.c              |    2 +-
 migration-tcp.c             |    2 +-
 migration-unix.c            |    2 +-
 module.c                    |    2 +-
 monitor.c                   |   10 +++++-----
 net/slirp.c                 |    6 +++---
 qapi/qapi-dealloc-visitor.c |    4 ++--
 qapi/qmp-input-visitor.c    |    4 ++--
 qapi/qmp-output-visitor.c   |    4 ++--
 qapi/qmp-registry.c         |    2 +-
 qbool.c                     |    2 +-
 qdict.c                     |    4 ++--
 qemu-char.c                 |    4 ++--
 qemu-io.c                   |    6 +++---
 qemu-option.c               |    4 ++--
 qemu-thread-win32.c         |    2 +-
 qerror.c                    |    2 +-
 qfloat.c                    |    2 +-
 qint.c                      |    2 +-
 qlist.c                     |    4 ++--
 qmp.c                       |    8 ++++----
 qstring.c                   |    2 +-
 readline.c                  |    2 +-
 target-xtensa/helper.c      |    2 +-
 ui/keymaps.c                |    2 +-
 ui/spice-core.c             |    6 +++---
 ui/spice-display.c          |    2 +-
 ui/spice-input.c            |    4 ++--
 ui/vnc-palette.c            |    2 +-
 ui/vnc.c                    |    2 +-
 usb-linux.c                 |    2 +-
 vl.c                        |    4 ++--
 xen-all.c                   |    4 ++--
 90 files changed, 148 insertions(+), 152 deletions(-)

diff --git a/acl.c b/acl.c
index 0654f38..83788bd 100644
--- a/acl.c
+++ b/acl.c
@@ -55,7 +55,7 @@ qemu_acl *qemu_acl_init(const char *aclname)
     if (acl)
         return acl;
 
-    acl = g_malloc(sizeof(*acl));
+    acl = g_new(qemu_acl, 1);
     acl->aclname = g_strdup(aclname);
     /* Deny by default, so there is no window of "open
      * access" between QEMU starting, and the user setting
@@ -116,7 +116,7 @@ int qemu_acl_append(qemu_acl *acl,
 {
     qemu_acl_entry *entry;
 
-    entry = g_malloc(sizeof(*entry));
+    entry = g_new(qemu_acl_entry, 1);
     entry->match = g_strdup(match);
     entry->deny = deny;
 
@@ -142,7 +142,7 @@ int qemu_acl_insert(qemu_acl *acl,
         return qemu_acl_append(acl, deny, match);
 
 
-    entry = g_malloc(sizeof(*entry));
+    entry = g_new(qemu_acl_entry, 1);
     entry->match = g_strdup(match);
     entry->deny = deny;
 
diff --git a/arch_init.c b/arch_init.c
index a6c69c7..13d572f 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -237,7 +237,7 @@ static void sort_ram_list(void)
     QLIST_FOREACH(block, &ram_list.blocks, next) {
         ++n;
     }
-    blocks = g_malloc(n * sizeof *blocks);
+    blocks = g_new(RAMBlock *, n);
     n = 0;
     QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
         blocks[n++] = block;
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index 4f785f5..e11dd82 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -143,7 +143,7 @@ int wav_start_capture (CaptureState *s, const char *path, 
int freq,
     ops.capture = wav_capture;
     ops.destroy = wav_destroy;
 
-    wav = g_malloc0 (sizeof (*wav));
+    wav = g_new0(WAVState, 1);
 
     shift = bits16 + stereo;
     hdr[34] = bits16 ? 0x10 : 0x08;
diff --git a/block.c b/block.c
index 9873b57..cc69c87 100644
--- a/block.c
+++ b/block.c
@@ -2472,7 +2472,7 @@ static int multiwrite_merge(BlockDriverState *bs, 
BlockRequest *reqs,
 
         if (merge) {
             size_t size;
-            QEMUIOVector *qiov = g_malloc0(sizeof(*qiov));
+            QEMUIOVector *qiov = g_new0(QEMUIOVector, 1);
             qemu_iovec_init(qiov,
                 reqs[outidx].qiov->niov + reqs[i].qiov->niov + 1);
 
diff --git a/block/blkdebug.c b/block/blkdebug.c
index b3c5d42..d8ad4a8 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -214,7 +214,7 @@ static int add_rule(QemuOpts *opts, void *opaque)
     }
 
     /* Set attributes common for all actions */
-    rule = g_malloc0(sizeof(*rule));
+    rule = g_new0(struct BlkdebugRule, 1);
     *rule = (struct BlkdebugRule) {
         .event  = event,
         .action = d->action,
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 340a6f2..5723c48 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -49,7 +49,7 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int 
num_tables,
     Qcow2Cache *c;
     int i;
 
-    c = g_malloc0(sizeof(*c));
+    c = g_new0(Qcow2Cache, 1);
     c->size = num_tables;
     c->entries = g_malloc0(sizeof(*c->entries) * num_tables);
     c->writethrough = writethrough;
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
index f64b2af..1629cdf 100644
--- a/block/qed-cluster.c
+++ b/block/qed-cluster.c
@@ -152,7 +152,7 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, 
uint64_t pos,
         return;
     }
 
-    find_cluster_cb = g_malloc(sizeof(*find_cluster_cb));
+    find_cluster_cb = g_new(QEDFindClusterCB, 1);
     find_cluster_cb->s = s;
     find_cluster_cb->pos = pos;
     find_cluster_cb->len = len;
diff --git a/block/qed-l2-cache.c b/block/qed-l2-cache.c
index 02b81a2..aa1d2ef 100644
--- a/block/qed-l2-cache.c
+++ b/block/qed-l2-cache.c
@@ -89,7 +89,7 @@ CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache 
*l2_cache)
 {
     CachedL2Table *entry;
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(CachedL2Table, 1);
     entry->ref++;
 
     trace_qed_alloc_l2_cache_entry(l2_cache, entry);
diff --git a/block/rbd.c b/block/rbd.c
index 3068c82..fce09e6 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -800,7 +800,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
     int max_snaps = RBD_MAX_SNAPS;
 
     do {
-        snaps = g_malloc(sizeof(*snaps) * max_snaps);
+        snaps = g_new(rbd_snap_info_t, max_snaps);
         snap_count = rbd_snap_list(s->image, snaps, &max_snaps);
         if (snap_count < 0) {
             g_free(snaps);
diff --git a/block/sheepdog.c b/block/sheepdog.c
index ae857e2..313b995 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -369,7 +369,7 @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, 
SheepdogAIOCB *acb,
 {
     AIOReq *aio_req;
 
-    aio_req = g_malloc(sizeof(*aio_req));
+    aio_req = g_new(AIOReq, 1);
     aio_req->aiocb = acb;
     aio_req->iov_offset = iov_offset;
     aio_req->oid = oid;
@@ -1956,7 +1956,7 @@ static int sd_snapshot_list(BlockDriverState *bs, 
QEMUSnapshotInfo **psn_tab)
         goto out;
     }
 
-    sn_tab = g_malloc0(nr * sizeof(*sn_tab));
+    sn_tab = g_new0(QEMUSnapshotInfo, nr);
 
     /* calculate a vdi id with hash function */
     hval = fnv_64a_buf(s->name, strlen(s->name), FNV1A_64_INIT);
diff --git a/blockdev.c b/blockdev.c
index 0827bf7..a7eda8a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -432,7 +432,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
 
     /* init */
 
-    dinfo = g_malloc0(sizeof(*dinfo));
+    dinfo = g_new0(DriveInfo, 1);
     if ((buf = qemu_opts_id(opts)) != NULL) {
         dinfo->id = g_strdup(buf);
     } else {
diff --git a/buffered_file.c b/buffered_file.c
index 486af57..f9a0742 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -259,7 +259,7 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
 {
     QEMUFileBuffered *s;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(QEMUFileBuffered, 1);
 
     s->opaque = opaque;
     s->xfer_limit = bytes_per_sec / 10;
diff --git a/coroutine-gthread.c b/coroutine-gthread.c
index fdea27a..256e1f2 100644
--- a/coroutine-gthread.c
+++ b/coroutine-gthread.c
@@ -71,7 +71,7 @@ Coroutine *qemu_coroutine_new(void)
 {
     CoroutineGThread *co;
 
-    co = g_malloc0(sizeof(*co));
+    co = g_new0(CoroutineGThread, 1);
     co->thread = g_thread_create_full(coroutine_thread, co, 0, TRUE, TRUE,
                                       G_THREAD_PRIORITY_NORMAL, NULL);
     if (!co->thread) {
@@ -115,7 +115,7 @@ Coroutine *qemu_coroutine_self(void)
     CoroutineGThread *co = g_static_private_get(&coroutine_key);
 
     if (!co) {
-        co = g_malloc0(sizeof(*co));
+        co = g_new0(CoroutineGThread, 1);
         co->runnable = true;
         g_static_private_set(&coroutine_key, co, (GDestroyNotify)g_free);
     }
diff --git a/coroutine-ucontext.c b/coroutine-ucontext.c
index 2b8d3e9..e1b9a52 100644
--- a/coroutine-ucontext.c
+++ b/coroutine-ucontext.c
@@ -73,7 +73,7 @@ static CoroutineThreadState *coroutine_get_thread_state(void)
     CoroutineThreadState *s = pthread_getspecific(thread_state_key);
 
     if (!s) {
-        s = g_malloc0(sizeof(*s));
+        s = g_new0(CoroutineThreadState, 1);
         s->current = &s->leader.base;
         QLIST_INIT(&s->pool);
         pthread_setspecific(thread_state_key, s);
@@ -146,7 +146,7 @@ static Coroutine *coroutine_new(void)
         abort();
     }
 
-    co = g_malloc0(sizeof(*co));
+    co = g_new0(CoroutineUContext, 1);
     co->stack = g_malloc(stack_size);
     co->base.entry_arg = &old_env; /* stash away our jmp_buf */
 
diff --git a/coroutine-win32.c b/coroutine-win32.c
index 4179609..eaf75b4 100644
--- a/coroutine-win32.c
+++ b/coroutine-win32.c
@@ -64,7 +64,7 @@ Coroutine *qemu_coroutine_new(void)
     const size_t stack_size = 1 << 20;
     CoroutineWin32 *co;
 
-    co = g_malloc0(sizeof(*co));
+    co = g_new0(CoroutineWin32, 1);
     co->fiber = CreateFiber(stack_size, coroutine_trampoline, &co->base);
     return &co->base;
 }
diff --git a/error.c b/error.c
index 68c0039..dc18872 100644
--- a/error.c
+++ b/error.c
@@ -32,7 +32,7 @@ void error_set(Error **errp, const char *fmt, ...)
         return;
     }
 
-    err = g_malloc0(sizeof(*err));
+    err = g_new0(Error, 1);
 
     va_start(ap, fmt);
     err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap));
@@ -137,7 +137,7 @@ void error_set_qobject(Error **errp, QObject *obj)
     if (errp == NULL) {
         return;
     }
-    err = g_malloc0(sizeof(*err));
+    err = g_new0(Error, 1);
     err->obj = qobject_to_qdict(obj);
     qobject_incref(obj);
 
diff --git a/exec.c b/exec.c
index d0cbf15..790dc1a 100644
--- a/exec.c
+++ b/exec.c
@@ -1444,7 +1444,7 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong 
addr, target_ulong len,
                 TARGET_FMT_lx ", len=" TARGET_FMT_lu "\n", addr, len);
         return -EINVAL;
     }
-    wp = g_malloc(sizeof(*wp));
+    wp = g_new(CPUWatchpoint, 1);
 
     wp->vaddr = addr;
     wp->len_mask = len_mask;
@@ -1509,7 +1509,7 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc, 
int flags,
 #if defined(TARGET_HAS_ICE)
     CPUBreakpoint *bp;
 
-    bp = g_malloc(sizeof(*bp));
+    bp = g_new(CPUBreakpoint, 1);
 
     bp->pc = pc;
     bp->flags = flags;
@@ -2917,7 +2917,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, 
const char *name,
     RAMBlock *new_block, *block;
 
     size = TARGET_PAGE_ALIGN(size);
-    new_block = g_malloc0(sizeof(*new_block));
+    new_block = g_new0(RAMBlock, 1);
 
     if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
         char *id = dev->parent_bus->info->get_dev_path(dev);
@@ -3824,11 +3824,11 @@ static void io_mem_init(void)
 
 static void memory_map_init(void)
 {
-    system_memory = g_malloc(sizeof(*system_memory));
+    system_memory = g_new(MemoryRegion, 1);
     memory_region_init(system_memory, "system", INT64_MAX);
     set_system_memory_map(system_memory);
 
-    system_io = g_malloc(sizeof(*system_io));
+    system_io = g_new(MemoryRegion, 1);
     memory_region_init(system_io, "io", 65536);
     set_system_io_map(system_io);
 }
@@ -4044,7 +4044,7 @@ static QLIST_HEAD(map_client_list, MapClient) 
map_client_list
 
 void *cpu_register_map_client(void *opaque, void (*callback)(void *opaque))
 {
-    MapClient *client = g_malloc(sizeof(*client));
+    MapClient *client = g_new(MapClient, 1);
 
     client->opaque = opaque;
     client->callback = callback;
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index 768819f..b7993c2 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -66,7 +66,7 @@ int qemu_fsdev_add(QemuOpts *opts)
         return -1;
     }
 
-    fsle = g_malloc(sizeof(*fsle));
+    fsle = g_new(struct FsTypeListEntry, 1);
 
     fsle->fse.fsdev_id = g_strdup(fsdev_id);
     fsle->fse.path = g_strdup(path);
diff --git a/gdbstub.c b/gdbstub.c
index 717c7d9..9b8103b 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2886,7 +2886,7 @@ int gdbserver_start(const char *device)
         qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
 
         /* Initialize a monitor terminal for gdb */
-        mon_chr = g_malloc0(sizeof(*mon_chr));
+        mon_chr = g_new0(CharDriverState, 1);
         mon_chr->chr_write = gdb_monitor_write;
         monitor_init(mon_chr, 0);
     } else {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c01c31a..e276ecc 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2861,7 +2861,7 @@ static void v9fs_lock(void *opaque)
     V9fsPDU *pdu = opaque;
     V9fsState *s = pdu->s;
 
-    flock = g_malloc(sizeof(*flock));
+    flock = g_new(V9fsFlock, 1);
     pdu_unmarshal(pdu, offset, "dbdqqds", &fid, &flock->type,
                   &flock->flags, &flock->start, &flock->length,
                   &flock->proc_id, &flock->client_id);
@@ -2906,7 +2906,7 @@ static void v9fs_getlock(void *opaque)
     V9fsPDU *pdu = opaque;
     V9fsState *s = pdu->s;
 
-    glock = g_malloc(sizeof(*glock));
+    glock = g_new(V9fsGetlock, 1);
     pdu_unmarshal(pdu, offset, "dbqqds", &fid, &glock->type,
                   &glock->start, &glock->length, &glock->proc_id,
                   &glock->client_id);
diff --git a/hw/bt-hid.c b/hw/bt-hid.c
index 8d7a3da..4f75bd4 100644
--- a/hw/bt-hid.c
+++ b/hw/bt-hid.c
@@ -517,7 +517,7 @@ enum peripheral_minor_class {
 static struct bt_device_s *bt_hid_init(struct bt_scatternet_s *net,
                                        enum peripheral_minor_class minor)
 {
-    struct bt_hid_device_s *s = g_malloc0(sizeof(*s));
+    struct bt_hid_device_s *s = g_new0(struct bt_hid_device_s, 1);
     uint32_t class =
             /* Format type */
             (0 << 0) |
diff --git a/hw/bt-l2cap.c b/hw/bt-l2cap.c
index 2ccba60..48f0715 100644
--- a/hw/bt-l2cap.c
+++ b/hw/bt-l2cap.c
@@ -410,7 +410,7 @@ static struct l2cap_chan_s *l2cap_channel_open(struct 
l2cap_instance_s *l2cap,
 
         if (psm_info) {
             /* Device supports this use-case.  */
-            ch = g_malloc0(sizeof(*ch));
+            ch = g_new0(struct l2cap_chan_s, 1);
             ch->params.sdu_out = l2cap_bframe_out;
             ch->params.sdu_submit = l2cap_bframe_submit;
             ch->frame_in = l2cap_bframe_in;
@@ -1353,7 +1353,7 @@ void bt_l2cap_psm_register(struct bt_l2cap_device_s *dev, 
int psm, int min_mtu,
         exit(-1);
     }
 
-    new_psm = g_malloc0(sizeof(*new_psm));
+    new_psm = g_new0(struct bt_l2cap_psm_s, 1);
     new_psm->psm = psm;
     new_psm->min_mtu = min_mtu;
     new_psm->new_channel = new_channel;
diff --git a/hw/bt-sdp.c b/hw/bt-sdp.c
index 3e390ab..ca41470 100644
--- a/hw/bt-sdp.c
+++ b/hw/bt-sdp.c
@@ -708,10 +708,9 @@ static void sdp_service_record_build(struct 
sdp_service_record_s *record,
                         &record->uuids);
     }
     record->uuids = 1 << ffs(record->uuids - 1);
-    record->attribute_list =
-            g_malloc0(record->attributes * sizeof(*record->attribute_list));
-    record->uuid =
-            g_malloc0(record->uuids * sizeof(*record->uuid));
+    record->attribute_list = g_new0(struct sdp_service_attribute_s,
+                                    record->attributes);
+    record->uuid = g_new0(int, record->uuids);
     data = g_malloc(len);
 
     record->attributes = 0;
@@ -752,8 +751,7 @@ static void sdp_service_db_build(struct 
bt_l2cap_sdp_state_s *sdp,
     sdp->services = 0;
     while (service[sdp->services])
         sdp->services ++;
-    sdp->service_list =
-            g_malloc0(sdp->services * sizeof(*sdp->service_list));
+    sdp->service_list = g_new0(struct sdp_service_record_s, sdp->services);
 
     sdp->services = 0;
     while (*service) {
@@ -942,7 +940,7 @@ SERVICE(pnp,
 static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s *dev,
                 struct bt_l2cap_conn_params_s *params)
 {
-    struct bt_l2cap_sdp_state_s *sdp = g_malloc0(sizeof(*sdp));
+    struct bt_l2cap_sdp_state_s *sdp = g_new0(struct bt_l2cap_sdp_state_s, 1);
     struct sdp_def_service_s *services[] = {
         &sdp_service_sdp_s,
         &sdp_service_hid_s,
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index c7e365b..d62cee4 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2384,7 +2384,7 @@ static void map_linear_vram_bank(CirrusVGAState *s, 
unsigned bank)
         && !((s->vga.gr[0x0B] & 0x14) == 0x14)
         && !(s->vga.gr[0x0B] & 0x02)) {
 
-        mr = g_malloc(sizeof(*mr));
+        mr = g_new(MemoryRegion, 1);
         memory_region_init_alias(mr, names[bank], &s->vga.vram,
                                  s->cirrus_bank_base[bank], 0x8000);
         memory_region_add_subregion_overlap(
diff --git a/hw/etraxfs_dma.c b/hw/etraxfs_dma.c
index 02d0183..46d97f6 100644
--- a/hw/etraxfs_dma.c
+++ b/hw/etraxfs_dma.c
@@ -750,7 +750,7 @@ void *etraxfs_dmac_init(target_phys_addr_t base, int 
nr_channels)
 {
        struct fs_dma_ctrl *ctrl = NULL;
 
-       ctrl = g_malloc0(sizeof *ctrl);
+       ctrl = g_new0(struct fs_dma_ctrl, 1);
 
         ctrl->bh = qemu_bh_new(DMA_run, ctrl);
 
diff --git a/hw/grlib_irqmp.c b/hw/grlib_irqmp.c
index 9490a78..44c419d 100644
--- a/hw/grlib_irqmp.c
+++ b/hw/grlib_irqmp.c
@@ -345,7 +345,7 @@ static int grlib_irqmp_init(SysBusDevice *dev)
                                         grlib_irqmp_write,
                                         irqmp, DEVICE_NATIVE_ENDIAN);
 
-    irqmp->state = g_malloc0(sizeof *irqmp->state);
+    irqmp->state = g_new0(IRQMPState, 1);
 
     if (irqmp_regs < 0) {
         return -1;
diff --git a/hw/isa_mmio.c b/hw/isa_mmio.c
index fd755ab..65333ea 100644
--- a/hw/isa_mmio.c
+++ b/hw/isa_mmio.c
@@ -74,7 +74,7 @@ void isa_mmio_setup(MemoryRegion *mr, target_phys_addr_t size)
 
 void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size)
 {
-    MemoryRegion *mr = g_malloc(sizeof(*mr));
+    MemoryRegion *mr = g_new(MemoryRegion, 1);
 
     isa_mmio_setup(mr, size);
     memory_region_add_subregion(get_system_memory(), base, mr);
diff --git a/hw/loader.c b/hw/loader.c
index 5676c18..8dbdf7e 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -564,7 +564,7 @@ int rom_add_file(const char *file, const char *fw_dir,
     int rc, fd = -1;
     char devpath[100];
 
-    rom = g_malloc0(sizeof(*rom));
+    rom = g_new0(Rom, 1);
     rom->name = g_strdup(file);
     rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
     if (rom->path == NULL) {
@@ -630,7 +630,7 @@ int rom_add_blob(const char *name, const void *blob, size_t 
len,
 {
     Rom *rom;
 
-    rom = g_malloc0(sizeof(*rom));
+    rom = g_new0(Rom, 1);
     rom->name    = g_strdup(name);
     rom->addr    = addr;
     rom->romsize = len;
diff --git a/hw/msix.c b/hw/msix.c
index b15bafc..d482ebc 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -219,8 +219,7 @@ int msix_init(struct PCIDevice *dev, unsigned short 
nentries,
     if (nentries > MSIX_MAX_ENTRIES)
         return -EINVAL;
 
-    dev->msix_entry_used = g_malloc0(MSIX_MAX_ENTRIES *
-                                        sizeof *dev->msix_entry_used);
+    dev->msix_entry_used = g_new0(unsigned, MSIX_MAX_ENTRIES);
 
     dev->msix_table_page = g_malloc0(MSIX_PAGE_SIZE);
     msix_mask_all(dev, nentries);
diff --git a/hw/omap_l4.c b/hw/omap_l4.c
index a4a8883..e809352 100644
--- a/hw/omap_l4.c
+++ b/hw/omap_l4.c
@@ -128,7 +128,7 @@ struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int 
ta_num)
 
 #ifdef L4_MUX_HACK
     omap_l4_io_entries = 1;
-    omap_l4_io_entry = g_malloc0(125 * sizeof(*omap_l4_io_entry));
+    omap_l4_io_entry = g_new0(struct omap_l4_entry, 125);
 
     omap_cpu_io_entry =
             cpu_register_io_memory(omap_l4_io_readfn,
diff --git a/hw/omap_synctimer.c b/hw/omap_synctimer.c
index b47ca88..8e1d389 100644
--- a/hw/omap_synctimer.c
+++ b/hw/omap_synctimer.c
@@ -86,7 +86,7 @@ static CPUWriteMemoryFunc * const omap_synctimer_writefn[] = {
 struct omap_synctimer_s *omap_synctimer_init(struct omap_target_agent_s *ta,
                 struct omap_mpu_state_s *mpu, omap_clk fclk, omap_clk iclk)
 {
-    struct omap_synctimer_s *s = g_malloc0(sizeof(*s));
+    struct omap_synctimer_s *s = g_new0(struct omap_synctimer_s, 1);
 
     omap_synctimer_reset(s);
     omap_l4_attach(ta, 0, l4_register_io_memory(
diff --git a/hw/pc.c b/hw/pc.c
index f0802b7..ce533ea 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -987,16 +987,16 @@ void pc_memory_init(MemoryRegion *system_memory,
      * aliases to address portions of it, mostly for backwards compatiblity
      * with older qemus that used qemu_ram_alloc().
      */
-    ram = g_malloc(sizeof(*ram));
+    ram = g_new(MemoryRegion, 1);
     memory_region_init_ram(ram, NULL, "pc.ram",
                            below_4g_mem_size + above_4g_mem_size);
     *ram_memory = ram;
-    ram_below_4g = g_malloc(sizeof(*ram_below_4g));
+    ram_below_4g = g_new(MemoryRegion, 1);
     memory_region_init_alias(ram_below_4g, "ram-below-4g", ram,
                              0, below_4g_mem_size);
     memory_region_add_subregion(system_memory, 0, ram_below_4g);
     if (above_4g_mem_size > 0) {
-        ram_above_4g = g_malloc(sizeof(*ram_above_4g));
+        ram_above_4g = g_new(MemoryRegion, 1);
         memory_region_init_alias(ram_above_4g, "ram-above-4g", ram,
                                  below_4g_mem_size, above_4g_mem_size);
         memory_region_add_subregion(system_memory, 0x100000000ULL,
@@ -1016,7 +1016,7 @@ void pc_memory_init(MemoryRegion *system_memory,
         (bios_size % 65536) != 0) {
         goto bios_error;
     }
-    bios = g_malloc(sizeof(*bios));
+    bios = g_new(MemoryRegion, 1);
     memory_region_init_ram(bios, NULL, "pc.bios", bios_size);
     memory_region_set_readonly(bios, true);
     ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
@@ -1032,7 +1032,7 @@ void pc_memory_init(MemoryRegion *system_memory,
     isa_bios_size = bios_size;
     if (isa_bios_size > (128 * 1024))
         isa_bios_size = 128 * 1024;
-    isa_bios = g_malloc(sizeof(*isa_bios));
+    isa_bios = g_new(MemoryRegion, 1);
     memory_region_init_alias(isa_bios, "isa-bios", bios,
                              bios_size - isa_bios_size, isa_bios_size);
     memory_region_add_subregion_overlap(rom_memory,
@@ -1041,7 +1041,7 @@ void pc_memory_init(MemoryRegion *system_memory,
                                         1);
     memory_region_set_readonly(isa_bios, true);
 
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+    option_rom_mr = g_new(MemoryRegion, 1);
     memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE);
     memory_region_add_subregion_overlap(rom_memory,
                                         PC_ROM_MIN_VGA,
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index c89042f..cea69a0 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -130,7 +130,7 @@ static void pc_init1(MemoryRegion *system_memory,
                        pci_enabled ? rom_memory : system_memory, &ram_memory);
     }
 
-    gsi_state = g_malloc0(sizeof(*gsi_state));
+    gsi_state = g_new0(GSIState, 1);
     gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
 
     if (pci_enabled) {
diff --git a/hw/pci.c b/hw/pci.c
index 749e8d8..a27eec1 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -223,7 +223,7 @@ static int pcibus_reset(BusState *qbus)
 static void pci_host_bus_register(int domain, PCIBus *bus)
 {
     struct PCIHostBus *host;
-    host = g_malloc0(sizeof(*host));
+    host = g_new0(struct PCIHostBus, 1);
     host->domain = domain;
     host->bus = bus;
     QLIST_INSERT_HEAD(&host_buses, host, next);
@@ -288,7 +288,7 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name,
 {
     PCIBus *bus;
 
-    bus = g_malloc0(sizeof(*bus));
+    bus = g_new0(PCIBus, 1);
     bus->qbus.qdev_allocated = 1;
     pci_bus_new_inplace(bus, parent, name, address_space_mem,
                         address_space_io, devfn_min);
diff --git a/hw/pcie_port.c b/hw/pcie_port.c
index 8a36f5c..1cdd624 100644
--- a/hw/pcie_port.c
+++ b/hw/pcie_port.c
@@ -76,7 +76,7 @@ void pcie_chassis_create(uint8_t chassis_number)
     if (c) {
         return;
     }
-    c = g_malloc0(sizeof(*c));
+    c = g_new0(struct PCIEChassis, 1);
     c->number = chassis_number;
     QLIST_INIT(&c->slots);
     QLIST_INSERT_HEAD(&chassis, c, next);
diff --git a/hw/ppc405_boards.c b/hw/ppc405_boards.c
index 672e934..c478c7b 100644
--- a/hw/ppc405_boards.c
+++ b/hw/ppc405_boards.c
@@ -184,7 +184,7 @@ static void ref405ep_init (ram_addr_t ram_size,
     MemoryRegion *bios;
     MemoryRegion *sram = g_new(MemoryRegion, 1);
     ram_addr_t bdloc;
-    MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories));
+    MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
     target_phys_addr_t ram_bases[2], ram_sizes[2];
     target_ulong sram_size;
     long bios_size;
@@ -503,7 +503,7 @@ static void taihu_405ep_init(ram_addr_t ram_size,
     qemu_irq *pic;
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *bios;
-    MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories));
+    MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
     target_phys_addr_t ram_bases[2], ram_sizes[2];
     long bios_size;
     target_ulong kernel_base, initrd_base;
diff --git a/hw/ppc440.c b/hw/ppc440.c
index cd8a95d..483dedf 100644
--- a/hw/ppc440.c
+++ b/hw/ppc440.c
@@ -38,8 +38,7 @@ CPUState *ppc440ep_init(MemoryRegion *address_space_mem, 
ram_addr_t *ram_size,
                         PCIBus **pcip, const unsigned int pci_irq_nrs[4],
                         int do_init, const char *cpu_model)
 {
-    MemoryRegion *ram_memories
-        = g_malloc(PPC440EP_SDRAM_NR_BANKS * sizeof(*ram_memories));
+    MemoryRegion *ram_memories = g_new(MemoryRegion, PPC440EP_SDRAM_NR_BANKS);
     target_phys_addr_t ram_bases[PPC440EP_SDRAM_NR_BANKS];
     target_phys_addr_t ram_sizes[PPC440EP_SDRAM_NR_BANKS];
     CPUState *env;
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index f0b811c..98e4184 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -799,7 +799,7 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
 {
     GlobalProperty *g;
 
-    g = g_malloc0(sizeof(*g));
+    g = g_new0(GlobalProperty, 1);
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
diff --git a/hw/spapr.c b/hw/spapr.c
index b118975..b2b7a06 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -330,7 +330,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,
     long pteg_shift = 17;
     char *filename;
 
-    spapr = g_malloc(sizeof(*spapr));
+    spapr = g_new(sPAPREnvironment, 1);
     cpu_ppc_hypercall = emulate_spapr_hypercall;
 
     /* We place the device tree just below either the top of RAM, or
diff --git a/hw/sysbus.c b/hw/sysbus.c
index 4fab5a4..b270a89 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -166,7 +166,7 @@ void sysbus_register_dev(const char *name, size_t size, 
sysbus_initfn init)
 {
     SysBusDeviceInfo *info;
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(SysBusDeviceInfo, 1);
     info->qdev.name = g_strdup(name);
     info->qdev.size = size;
     info->init = init;
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index ae2d384..7ff3638 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -283,7 +283,7 @@ void usb_desc_set_string(USBDevice *dev, uint8_t index, 
const char *str)
         }
     }
     if (s == NULL) {
-        s = g_malloc0(sizeof(*s));
+        s = g_new0(USBDescString, 1);
         s->index = index;
         QLIST_INSERT_HEAD(&dev->strings, s, next);
     }
diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index bd374c1..501c9ff 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -660,7 +660,7 @@ static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, int 
async)
 {
     EHCIQueue *q;
 
-    q = g_malloc0(sizeof(*q));
+    q = g_new0(EHCIQueue, 1);
     q->ehci = ehci;
     q->async_schedule = async;
     QTAILQ_INSERT_HEAD(&ehci->queues, q, next);
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 01e2e7c..96b005f 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -374,7 +374,7 @@ void musb_reset(MUSBState *s)
 
 struct MUSBState *musb_init(DeviceState *parent_device, int gpio_base)
 {
-    MUSBState *s = g_malloc0(sizeof(*s));
+    MUSBState *s = g_new0(MUSBState, 1);
     int i;
 
     for (i = 0; i < musb_irq_max; i++) {
diff --git a/hw/vga-isa-mm.c b/hw/vga-isa-mm.c
index f8984c6..10f510b 100644
--- a/hw/vga-isa-mm.c
+++ b/hw/vga-isa-mm.c
@@ -102,11 +102,11 @@ static void vga_mm_init(ISAVGAMMState *s, 
target_phys_addr_t vram_base,
     MemoryRegion *s_ioport_ctrl, *vga_io_memory;
 
     s->it_shift = it_shift;
-    s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
+    s_ioport_ctrl = g_new(MemoryRegion, 1);
     memory_region_init_io(s_ioport_ctrl, &vga_mm_ctrl_ops, s,
                           "vga-mm-ctrl", 0x100000);
 
-    vga_io_memory = g_malloc(sizeof(*vga_io_memory));
+    vga_io_memory = g_new(MemoryRegion, 1);
     /* XXX: endianness? */
     memory_region_init_io(vga_io_memory, &vga_mem_ops, &s->vga,
                           "vga-mem", 0x20000);
@@ -126,7 +126,7 @@ int isa_vga_mm_init(target_phys_addr_t vram_base,
 {
     ISAVGAMMState *s;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(ISAVGAMMState, 1);
 
     vga_common_init(&s->vga, VGA_RAM_SIZE);
     vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
diff --git a/hw/vga.c b/hw/vga.c
index ca79aa1..b89bb1e 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -182,7 +182,7 @@ static void vga_update_memory_access(VGACommonState *s)
             break;
         }
         base += isa_mem_base;
-        region = g_malloc(sizeof(*region));
+        region = g_new(MemoryRegion, 1);
         memory_region_init_alias(region, "vga.chain4", &s->vram, offset, size);
         memory_region_add_subregion_overlap(s->legacy_address_space, base,
                                             region, 2);
@@ -2279,7 +2279,7 @@ MemoryRegion *vga_init_io(VGACommonState *s,
     *vbe_ports = vbe_portio_list;
 #endif
 
-    vga_mem = g_malloc(sizeof(*vga_mem));
+    vga_mem = g_new(MemoryRegion, 1);
     memory_region_init_io(vga_mem, &vga_mem_ops, s,
                           "vga-lowmem", 0x20000);
 
diff --git a/hw/vhost.c b/hw/vhost.c
index 0870cb7..30c48c7 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -252,7 +252,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev* 
dev, uint64_t size)
     uint64_t log_base;
     int r;
     if (size) {
-        log = g_malloc0(size * sizeof *log);
+        log = g_new0(vhost_log_chunk_t, size);
     } else {
         log = NULL;
     }
diff --git a/hw/vhost_net.c b/hw/vhost_net.c
index 950a6b8..4db5ae1 100644
--- a/hw/vhost_net.c
+++ b/hw/vhost_net.c
@@ -92,7 +92,7 @@ struct vhost_net *vhost_net_init(VLANClientState *backend, 
int devfd,
                                  bool force)
 {
     int r;
-    struct vhost_net *net = g_malloc(sizeof *net);
+    struct vhost_net *net = g_new(struct vhost_net, 1);
     if (!backend) {
         fprintf(stderr, "vhost-net requires backend to be setup\n");
         goto fail;
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 2a5d1a9..f11130a 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -123,7 +123,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
 
 static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
 {
-    VirtIOBlockReq *req = g_malloc(sizeof(*req));
+    VirtIOBlockReq *req = g_new(VirtIOBlockReq, 1);
     req->dev = s;
     req->qiov.size = 0;
     req->next = NULL;
diff --git a/hw/xen_devconfig.c b/hw/xen_devconfig.c
index 41accbb..0a57a4a 100644
--- a/hw/xen_devconfig.c
+++ b/hw/xen_devconfig.c
@@ -14,7 +14,7 @@ static void xen_config_cleanup_dir(char *dir)
 {
     struct xs_dirs *d;
 
-    d = g_malloc(sizeof(*d));
+    d = g_new(struct xs_dirs, 1);
     d->xs_dir = dir;
     QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
 }
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index 8a9fac4..1146c70 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -125,7 +125,7 @@ static struct ioreq *ioreq_start(struct XenBlkDev *blkdev)
             goto out;
         }
         /* allocate new struct */
-        ioreq = g_malloc0(sizeof(*ioreq));
+        ioreq = g_new0(struct ioreq, 1);
         ioreq->blkdev = blkdev;
         blkdev->requests_total++;
         qemu_iovec_init(&ioreq->v, BLKIF_MAX_SEGMENTS_PER_REQUEST);
diff --git a/hw/xics.c b/hw/xics.c
index 1c5eaa4..29f2c78 100644
--- a/hw/xics.c
+++ b/hw/xics.c
@@ -437,7 +437,7 @@ struct icp_state *xics_system_init(int nr_irqs)
         }
     }
 
-    icp = g_malloc0(sizeof(*icp));
+    icp = g_new0(struct icp_state, 1);
     icp->nr_servers = max_server_num + 1;
     icp->ss = g_malloc0(icp->nr_servers*sizeof(struct icp_server_state));
 
@@ -464,7 +464,7 @@ struct icp_state *xics_system_init(int nr_irqs)
         }
     }
 
-    ics = g_malloc0(sizeof(*ics));
+    ics = g_new0(struct ics_state, 1);
     ics->nr_irqs = nr_irqs;
     ics->offset = 16;
     ics->irqs = g_malloc0(nr_irqs * sizeof(struct ics_irq_state));
diff --git a/hw/xtensa_lx60.c b/hw/xtensa_lx60.c
index 3cebca1..424ddf2 100644
--- a/hw/xtensa_lx60.c
+++ b/hw/xtensa_lx60.c
@@ -127,7 +127,7 @@ static void lx60_net_init(MemoryRegion *address_space,
     memory_region_add_subregion(address_space, descriptors,
             sysbus_mmio_get_region(s, 1));
 
-    ram = g_malloc(sizeof(*ram));
+    ram = g_new(MemoryRegion, 1);
     memory_region_init_ram(ram, NULL, "open_eth.ram", 16384);
     memory_region_add_subregion(address_space, buffers, ram);
 }
@@ -171,15 +171,15 @@ static void lx60_init(ram_addr_t ram_size,
         cpu_reset(env);
     }
 
-    ram = g_malloc(sizeof(*ram));
+    ram = g_new(MemoryRegion, 1);
     memory_region_init_ram(ram, NULL, "xtensa.sram", ram_size);
     memory_region_add_subregion(system_memory, 0, ram);
 
-    rom = g_malloc(sizeof(*rom));
+    rom = g_new(MemoryRegion, 1);
     memory_region_init_ram(rom, NULL, "xtensa.rom", 0x1000);
     memory_region_add_subregion(system_memory, 0xfe000000, rom);
 
-    system_io = g_malloc(sizeof(*system_io));
+    system_io = g_new(MemoryRegion, 1);
     memory_region_init(system_io, "system.io", 224 * 1024 * 1024);
     memory_region_add_subregion(system_memory, 0xf0000000, system_io);
     lx60_fpga_init(system_io, 0x0d020000);
diff --git a/hw/xtensa_sim.c b/hw/xtensa_sim.c
index a94e4e5..a9188e9 100644
--- a/hw/xtensa_sim.c
+++ b/hw/xtensa_sim.c
@@ -65,11 +65,11 @@ static void sim_init(ram_addr_t ram_size,
         sim_reset(env);
     }
 
-    ram = g_malloc(sizeof(*ram));
+    ram = g_new(MemoryRegion, 1);
     memory_region_init_ram(ram, NULL, "xtensa.sram", ram_size);
     memory_region_add_subregion(get_system_memory(), 0, ram);
 
-    rom = g_malloc(sizeof(*rom));
+    rom = g_new(MemoryRegion, 1);
     memory_region_init_ram(rom, NULL, "xtensa.rom", 0x1000);
     memory_region_add_subregion(get_system_memory(), 0xfe000000, rom);
 
diff --git a/linux-aio.c b/linux-aio.c
index 1c635ef..e4101e2 100644
--- a/linux-aio.c
+++ b/linux-aio.c
@@ -207,7 +207,7 @@ void *laio_init(void)
 {
     struct qemu_laio_state *s;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(struct qemu_laio_state, 1);
     s->efd = eventfd(0, 0);
     if (s->efd == -1)
         goto out_free_state;
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8677bba..56abc8c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2115,7 +2115,7 @@ static struct mm_struct *vma_init(void)
 {
     struct mm_struct *mm;
 
-    if ((mm = g_malloc(sizeof (*mm))) == NULL)
+    if ((mm = g_new(struct mm_struct, 1)) == NULL)
         return (NULL);
 
     mm->mm_count = 0;
@@ -2140,7 +2140,7 @@ static int vma_add_mapping(struct mm_struct *mm, 
abi_ulong start,
 {
     struct vm_area_struct *vma;
 
-    if ((vma = g_malloc0(sizeof (*vma))) == NULL)
+    if ((vma = g_new0(struct vm_area_struct, 1)) == NULL)
         return (-1);
 
     vma->vma_start = start;
@@ -2464,7 +2464,7 @@ static void fill_thread_info(struct elf_note_info *info, 
const CPUState *env)
     TaskState *ts = (TaskState *)env->opaque;
     struct elf_thread_status *ets;
 
-    ets = g_malloc0(sizeof (*ets));
+    ets = g_new0(struct elf_thread_status, 1);
     ets->num_notes = 1; /* only prstatus is dumped */
     fill_prstatus(&ets->prstatus, ts, 0);
     elf_core_copy_regs(&ets->prstatus.pr_reg, env);
diff --git a/memory.c b/memory.c
index dc5e35d..51017d5 100644
--- a/memory.c
+++ b/memory.c
@@ -1123,7 +1123,7 @@ void memory_region_add_coalescing(MemoryRegion *mr,
                                   target_phys_addr_t offset,
                                   uint64_t size)
 {
-    CoalescedMemoryRange *cmr = g_malloc(sizeof(*cmr));
+    CoalescedMemoryRange *cmr = g_new(CoalescedMemoryRange, 1);
 
     cmr->addr = addrrange_make(offset, size);
     QTAILQ_INSERT_TAIL(&mr->coalesced, cmr, link);
diff --git a/migration-exec.c b/migration-exec.c
index 2cfb6f2..ccb5dee 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -71,7 +71,7 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon,
     FdMigrationState *s;
     FILE *f;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(FdMigrationState, 1);
 
     f = popen(command, "w");
     if (f == NULL) {
diff --git a/migration-fd.c b/migration-fd.c
index aee690a..6ae2c68 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -59,7 +59,7 @@ MigrationState *fd_start_outgoing_migration(Monitor *mon,
 {
     FdMigrationState *s;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(FdMigrationState, 1);
 
     s->fd = monitor_get_fd(mon, fdname);
     if (s->fd == -1) {
diff --git a/migration-tcp.c b/migration-tcp.c
index c431e03..5f03aee 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -89,7 +89,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,
     if (parse_host_port(&addr, host_port) < 0)
         return NULL;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(FdMigrationState, 1);
 
     s->get_error = socket_errno;
     s->write = socket_write;
diff --git a/migration-unix.c b/migration-unix.c
index 6dc985d..905d2b1 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -88,7 +88,7 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon,
     addr.sun_family = AF_UNIX;
     snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(FdMigrationState, 1);
 
     s->get_error = unix_errno;
     s->write = unix_write;
diff --git a/module.c b/module.c
index 91f0e61..50eb77f 100644
--- a/module.c
+++ b/module.c
@@ -59,7 +59,7 @@ void register_module_init(void (*fn)(void), module_init_type 
type)
     ModuleEntry *e;
     ModuleTypeList *l;
 
-    e = g_malloc0(sizeof(*e));
+    e = g_new0(ModuleEntry, 1);
     e->init = fn;
 
     l = find_type(type);
diff --git a/monitor.c b/monitor.c
index ffda0fe..1732616 100644
--- a/monitor.c
+++ b/monitor.c
@@ -674,7 +674,7 @@ static void user_async_cmd_handler(Monitor *mon, const 
mon_cmd_t *cmd,
 {
     int ret;
 
-    MonitorCompletionData *cb_data = g_malloc(sizeof(*cb_data));
+    MonitorCompletionData *cb_data = g_new(MonitorCompletionData, 1);
     cb_data->mon = mon;
     cb_data->user_print = cmd->user_print;
     monitor_suspend(mon);
@@ -690,7 +690,7 @@ static void user_async_info_handler(Monitor *mon, const 
mon_cmd_t *cmd)
 {
     int ret;
 
-    MonitorCompletionData *cb_data = g_malloc(sizeof(*cb_data));
+    MonitorCompletionData *cb_data = g_new(MonitorCompletionData, 1);
     cb_data->mon = mon;
     cb_data->user_print = cmd->user_print;
     monitor_suspend(mon);
@@ -743,7 +743,7 @@ static CommandInfoList *alloc_cmd_entry(const char 
*cmd_name)
 {
     CommandInfoList *info;
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CommandInfoList, 1);
     info->value = g_malloc0(sizeof(*info->value));
     info->value->name = g_strdup(cmd_name);
 
@@ -2480,7 +2480,7 @@ static void do_wav_capture(Monitor *mon, const QDict 
*qdict)
     int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
     CaptureState *s;
 
-    s = g_malloc0 (sizeof (*s));
+    s = g_new0(CaptureState, 1);
 
     freq = has_freq ? freq : 44100;
     bits = has_bits ? bits : 16;
@@ -5114,7 +5114,7 @@ void monitor_init(CharDriverState *chr, int flags)
         is_first_init = 0;
     }
 
-    mon = g_malloc0(sizeof(*mon));
+    mon = g_new0(Monitor, 1);
 
     mon->chr = chr;
     mon->flags = flags;
diff --git a/net/slirp.c b/net/slirp.c
index c6cda5d..ce29404 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -450,7 +450,7 @@ int net_slirp_redir(const char *redir_str)
     struct slirp_config_str *config;
 
     if (QTAILQ_EMPTY(&slirp_stacks)) {
-        config = g_malloc(sizeof(*config));
+        config = g_new(struct slirp_config_str, 1);
         pstrcpy(config->str, sizeof(config->str), redir_str);
         config->flags = SLIRP_CFG_HOSTFWD | SLIRP_CFG_LEGACY;
         config->next = slirp_configs;
@@ -662,7 +662,7 @@ static int net_init_slirp_configs(const char *name, const 
char *value, void *opa
         return 0;
     }
 
-    config = g_malloc0(sizeof(*config));
+    config = g_new0(struct slirp_config_str, 1);
 
     pstrcpy(config->str, sizeof(config->str), value);
 
@@ -764,7 +764,7 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const 
char *optarg, int *ret
     if (QTAILQ_EMPTY(&slirp_stacks)) {
         struct slirp_config_str *config;
 
-        config = g_malloc(sizeof(*config));
+        config = g_new(struct slirp_config_str, 1);
         pstrcpy(config->str, sizeof(config->str), optarg);
         config->flags = SLIRP_CFG_LEGACY;
         config->next = slirp_configs;
diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
index a154523..7ed00a9 100644
--- a/qapi/qapi-dealloc-visitor.c
+++ b/qapi/qapi-dealloc-visitor.c
@@ -37,7 +37,7 @@ static QapiDeallocVisitor *to_qov(Visitor *v)
 
 static void qapi_dealloc_push(QapiDeallocVisitor *qov, void *value)
 {
-    StackEntry *e = g_malloc0(sizeof(*e));
+    StackEntry *e = g_new0(StackEntry, 1);
 
     e->value = value;
 
@@ -152,7 +152,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void)
 {
     QapiDeallocVisitor *v;
 
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(QapiDeallocVisitor, 1);
 
     v->visitor.start_struct = qapi_dealloc_start_struct;
     v->visitor.end_struct = qapi_dealloc_end_struct;
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index 8cbc0ab..9ea1d90 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -135,7 +135,7 @@ static GenericList *qmp_input_next_list(Visitor *v, 
GenericList **list,
         return NULL;
     }
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(GenericList, 1);
     if (*list) {
         so->entry = qlist_next(so->entry);
         if (so->entry == NULL) {
@@ -279,7 +279,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj)
 {
     QmpInputVisitor *v;
 
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(QmpInputVisitor, 1);
 
     v->visitor.start_struct = qmp_input_start_struct;
     v->visitor.end_struct = qmp_input_end_struct;
diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
index d67724e..ea4465a 100644
--- a/qapi/qmp-output-visitor.c
+++ b/qapi/qmp-output-visitor.c
@@ -43,7 +43,7 @@ static QmpOutputVisitor *to_qov(Visitor *v)
 
 static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value)
 {
-    QStackEntry *e = g_malloc0(sizeof(*e));
+    QStackEntry *e = g_new0(QStackEntry, 1);
 
     e->value = value;
     if (qobject_type(e->value) == QTYPE_QLIST) {
@@ -232,7 +232,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void)
 {
     QmpOutputVisitor *v;
 
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(QmpOutputVisitor, 1);
 
     v->visitor.start_struct = qmp_output_start_struct;
     v->visitor.end_struct = qmp_output_end_struct;
diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c
index 5ff99cf..e84a701 100644
--- a/qapi/qmp-registry.c
+++ b/qapi/qmp-registry.c
@@ -19,7 +19,7 @@ static QTAILQ_HEAD(, QmpCommand) qmp_commands =
 
 void qmp_register_command(const char *name, QmpCommandFunc *fn)
 {
-    QmpCommand *cmd = g_malloc0(sizeof(*cmd));
+    QmpCommand *cmd = g_new0(QmpCommand, 1);
 
     cmd->name = name;
     cmd->type = QCT_NORMAL;
diff --git a/qbool.c b/qbool.c
index 590cd71..abbd01b 100644
--- a/qbool.c
+++ b/qbool.c
@@ -31,7 +31,7 @@ QBool *qbool_from_int(int value)
 {
     QBool *qb;
 
-    qb = g_malloc(sizeof(*qb));
+    qb = g_new(QBool, 1);
     qb->value = value;
     QOBJECT_INIT(qb, &qbool_type);
 
diff --git a/qdict.c b/qdict.c
index 4bf308b..391ae32 100644
--- a/qdict.c
+++ b/qdict.c
@@ -35,7 +35,7 @@ QDict *qdict_new(void)
 {
     QDict *qdict;
 
-    qdict = g_malloc0(sizeof(*qdict));
+    qdict = g_new0(QDict, 1);
     QOBJECT_INIT(qdict, &qdict_type);
 
     return qdict;
@@ -75,7 +75,7 @@ static QDictEntry *alloc_entry(const char *key, QObject 
*value)
 {
     QDictEntry *entry;
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(QDictEntry, 1);
     entry->key = g_strdup(key);
     entry->value = value;
 
diff --git a/qemu-char.c b/qemu-char.c
index fb9e058..ab75c21 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2348,7 +2348,7 @@ void qemu_chr_init_mem(CharDriverState *chr)
 {
     MemoryDriver *d;
 
-    d = g_malloc(sizeof(*d));
+    d = g_new(MemoryDriver, 1);
     d->outbuf_size = 0;
     d->outbuf_capacity = 4096;
     d->outbuf = g_malloc0(d->outbuf_capacity);
@@ -2656,7 +2656,7 @@ ChardevInfoList *qmp_query_chardev(Error **errp)
     CharDriverState *chr;
 
     QTAILQ_FOREACH(chr, &chardevs, next) {
-        ChardevInfoList *info = g_malloc0(sizeof(*info));
+        ChardevInfoList *info = g_new0(ChardevInfoList, 1);
         info->value = g_malloc0(sizeof(*info->value));
         info->value->label = g_strdup(chr->label);
         info->value->filename = g_strdup(chr->filename);
diff --git a/qemu-io.c b/qemu-io.c
index e91af37..804ac06 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -950,9 +950,9 @@ static int multiwrite_f(int argc, char **argv)
         }
     }
 
-    reqs = g_malloc(nr_reqs * sizeof(*reqs));
-    buf = g_malloc(nr_reqs * sizeof(*buf));
-    qiovs = g_malloc(nr_reqs * sizeof(*qiovs));
+    reqs = g_new(BlockRequest, nr_reqs);
+    buf = g_new(char *, nr_reqs);
+    qiovs = g_new(QEMUIOVector, nr_reqs);
 
     for (i = 0; i < nr_reqs; i++) {
         int j;
diff --git a/qemu-option.c b/qemu-option.c
index 105d760..2fade1d 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -619,7 +619,7 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const 
char *value)
         }
     }
 
-    opt = g_malloc0(sizeof(*opt));
+    opt = g_new0(QemuOpt, 1);
     opt->name = g_strdup(name);
     opt->opts = opts;
     QTAILQ_INSERT_TAIL(&opts->head, opt, next);
@@ -701,7 +701,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char 
*id, int fail_if_exist
             }
         }
     }
-    opts = g_malloc0(sizeof(*opts));
+    opts = g_new0(QemuOpts, 1);
     if (id) {
         opts->id = g_strdup(id);
     }
diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c
index db8e744..9a6a41c 100644
--- a/qemu-thread-win32.c
+++ b/qemu-thread-win32.c
@@ -249,7 +249,7 @@ void qemu_thread_create(QemuThread *thread,
 
     struct QemuThreadData *data;
     qemu_thread_init();
-    data = g_malloc(sizeof *data);
+    data = g_new(struct QemuThreadData, 1);
     data->thread = thread;
     data->start_routine = start_routine;
     data->arg = arg;
diff --git a/qerror.c b/qerror.c
index 68998d4..761626c 100644
--- a/qerror.c
+++ b/qerror.c
@@ -246,7 +246,7 @@ QError *qerror_new(void)
 {
     QError *qerr;
 
-    qerr = g_malloc0(sizeof(*qerr));
+    qerr = g_new0(QError, 1);
     QOBJECT_INIT(qerr, &qerror_type);
 
     return qerr;
diff --git a/qfloat.c b/qfloat.c
index 98338f3..4610c6b 100644
--- a/qfloat.c
+++ b/qfloat.c
@@ -31,7 +31,7 @@ QFloat *qfloat_from_double(double value)
 {
     QFloat *qf;
 
-    qf = g_malloc(sizeof(*qf));
+    qf = g_new(QFloat, 1);
     qf->value = value;
     QOBJECT_INIT(qf, &qfloat_type);
 
diff --git a/qint.c b/qint.c
index ee51804..06a080b 100644
--- a/qint.c
+++ b/qint.c
@@ -30,7 +30,7 @@ QInt *qint_from_int(int64_t value)
 {
     QInt *qi;
 
-    qi = g_malloc(sizeof(*qi));
+    qi = g_new(QInt, 1);
     qi->value = value;
     QOBJECT_INIT(qi, &qint_type);
 
diff --git a/qlist.c b/qlist.c
index 88498b1..cf3dcf8 100644
--- a/qlist.c
+++ b/qlist.c
@@ -31,7 +31,7 @@ QList *qlist_new(void)
 {
     QList *qlist;
 
-    qlist = g_malloc(sizeof(*qlist));
+    qlist = g_new(QList, 1);
     QTAILQ_INIT(&qlist->head);
     QOBJECT_INIT(qlist, &qlist_type);
 
@@ -64,7 +64,7 @@ void qlist_append_obj(QList *qlist, QObject *value)
 {
     QListEntry *entry;
 
-    entry = g_malloc(sizeof(*entry));
+    entry = g_new(QListEntry, 1);
     entry->value = value;
 
     QTAILQ_INSERT_TAIL(&qlist->head, entry, next);
diff --git a/qmp.c b/qmp.c
index bf58b05..f840379 100644
--- a/qmp.c
+++ b/qmp.c
@@ -19,7 +19,7 @@
 
 NameInfo *qmp_query_name(Error **errp)
 {
-    NameInfo *info = g_malloc0(sizeof(*info));
+    NameInfo *info = g_new0(NameInfo, 1);
 
     if (qemu_name) {
         info->has_name = true;
@@ -31,7 +31,7 @@ NameInfo *qmp_query_name(Error **errp)
 
 VersionInfo *qmp_query_version(Error **err)
 {
-    VersionInfo *info = g_malloc0(sizeof(*info));
+    VersionInfo *info = g_new0(VersionInfo, 1);
     const char *version = QEMU_VERSION;
     char *tmp;
 
@@ -47,7 +47,7 @@ VersionInfo *qmp_query_version(Error **err)
 
 KvmInfo *qmp_query_kvm(Error **errp)
 {
-    KvmInfo *info = g_malloc0(sizeof(*info));
+    KvmInfo *info = g_new0(KvmInfo, 1);
 
     info->enabled = kvm_enabled();
     info->present = kvm_available();
@@ -57,7 +57,7 @@ KvmInfo *qmp_query_kvm(Error **errp)
 
 UuidInfo *qmp_query_uuid(Error **errp)
 {
-    UuidInfo *info = g_malloc0(sizeof(*info));
+    UuidInfo *info = g_new0(UuidInfo, 1);
     char uuid[64];
 
     snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
diff --git a/qstring.c b/qstring.c
index b7e12e4..ea076c1 100644
--- a/qstring.c
+++ b/qstring.c
@@ -40,7 +40,7 @@ QString *qstring_from_substr(const char *str, int start, int 
end)
 {
     QString *qstring;
 
-    qstring = g_malloc(sizeof(*qstring));
+    qstring = g_new(QString, 1);
 
     qstring->length = end - start + 1;
     qstring->capacity = qstring->length;
diff --git a/readline.c b/readline.c
index 6a3160a..bb4a756 100644
--- a/readline.c
+++ b/readline.c
@@ -466,7 +466,7 @@ const char *readline_get_history(ReadLineState *rs, 
unsigned int index)
 ReadLineState *readline_init(Monitor *mon,
                              ReadLineCompletionFunc *completion_finder)
 {
-    ReadLineState *rs = g_malloc0(sizeof(*rs));
+    ReadLineState *rs = g_new0(ReadLineState, 1);
 
     rs->hist_entry = -1;
     rs->mon = mon;
diff --git a/target-xtensa/helper.c b/target-xtensa/helper.c
index fc85815..445e61b 100644
--- a/target-xtensa/helper.c
+++ b/target-xtensa/helper.c
@@ -74,7 +74,7 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model)
         return NULL;
     }
 
-    env = g_malloc0(sizeof(*env));
+    env = g_new0(CPUXtensaState, 1);
     env->config = config;
     cpu_exec_init(env);
 
diff --git a/ui/keymaps.c b/ui/keymaps.c
index f54a114..54bfee7 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -52,7 +52,7 @@ static void add_to_key_range(struct key_range **krp, int 
code) {
        }
     }
     if (kr == NULL) {
-       kr = g_malloc0(sizeof(*kr));
+       kr = g_new0(struct key_range, 1);
         kr->start = kr->end = code;
         kr->next = *krp;
         *krp = kr;
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 3cbc721..14bb233 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -57,7 +57,7 @@ static SpiceTimer *timer_add(SpiceTimerFunc func, void 
*opaque)
 {
     SpiceTimer *timer;
 
-    timer = g_malloc0(sizeof(*timer));
+    timer = g_new0(SpiceTimer, 1);
     timer->timer = qemu_new_timer_ms(rt_clock, func, opaque);
     QTAILQ_INSERT_TAIL(&timers, timer, next);
     return timer;
@@ -121,7 +121,7 @@ static SpiceWatch *watch_add(int fd, int event_mask, 
SpiceWatchFunc func, void *
 {
     SpiceWatch *watch;
 
-    watch = g_malloc0(sizeof(*watch));
+    watch = g_new0(SpiceWatch, 1);
     watch->fd     = fd;
     watch->func   = func;
     watch->opaque = opaque;
@@ -151,7 +151,7 @@ static void channel_list_add(SpiceChannelEventInfo *info)
 {
     ChannelList *item;
 
-    item = g_malloc0(sizeof(*item));
+    item = g_new0(ChannelList, 1);
     item->info = info;
     QTAILQ_INSERT_TAIL(&channel_list, item, link);
 }
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 6c302a3..60e8214 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -142,7 +142,7 @@ static SimpleSpiceUpdate 
*qemu_spice_create_update(SimpleSpiceDisplay *ssd)
            ssd->dirty.left, ssd->dirty.right,
            ssd->dirty.top, ssd->dirty.bottom);
 
-    update   = g_malloc0(sizeof(*update));
+    update = g_new0(SimpleSpiceUpdate, 1);
     drawable = &update->drawable;
     image    = &update->image;
     cmd      = &update->ext.cmd;
diff --git a/ui/spice-input.c b/ui/spice-input.c
index af4223d..76df659 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -200,12 +200,12 @@ void qemu_spice_input_init(void)
     QemuSpiceKbd *kbd;
     QemuSpicePointer *pointer;
 
-    kbd = g_malloc0(sizeof(*kbd));
+    kbd = g_new0(QemuSpiceKbd, 1);
     kbd->sin.base.sif = &kbd_interface.base;
     qemu_spice_add_interface(&kbd->sin.base);
     qemu_add_led_event_handler(kbd_leds, kbd);
 
-    pointer = g_malloc0(sizeof(*pointer));
+    pointer = g_new0(QemuSpicePointer, 1);
     pointer->mouse.base.sif  = &mouse_interface.base;
     pointer->tablet.base.sif = &tablet_interface.base;
     qemu_spice_add_interface(&pointer->mouse.base);
diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index 63d5f64..64176a9 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -55,7 +55,7 @@ VncPalette *palette_new(size_t max, int bpp)
 {
     VncPalette *palette;
 
-    palette = g_malloc0(sizeof(*palette));
+    palette = g_new0(VncPalette, 1);
     palette_init(palette, max, bpp);
     return palette;
 }
diff --git a/ui/vnc.c b/ui/vnc.c
index fc3a612..2ae9121 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2576,7 +2576,7 @@ static void vnc_listen_read(void *opaque)
 
 void vnc_display_init(DisplayState *ds)
 {
-    VncDisplay *vs = g_malloc0(sizeof(*vs));
+    VncDisplay *vs = g_new0(VncDisplay, 1);
 
     dcl = g_malloc0(sizeof(DisplayChangeListener));
 
diff --git a/usb-linux.c b/usb-linux.c
index 7d4d1d7..77c0252 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -632,7 +632,7 @@ static AsyncURB *usb_host_alloc_iso(USBHostDevice *s, int 
pid, uint8_t ep)
     AsyncURB *aurb;
     int i, j, len = get_max_packet_size(s, pid, ep);
 
-    aurb = g_malloc0(s->iso_urb_count * sizeof(*aurb));
+    aurb = g_new0(AsyncURB, s->iso_urb_count);
     for (i = 0; i < s->iso_urb_count; i++) {
         aurb[i].urb.endpoint      = ep;
         aurb[i].urb.buffer_length = ISO_FRAME_DESC_PER_URB * len;
diff --git a/vl.c b/vl.c
index 2dce3ae..df96c11 100644
--- a/vl.c
+++ b/vl.c
@@ -409,7 +409,7 @@ int runstate_is_running(void)
 
 StatusInfo *qmp_query_status(Error **errp)
 {
-    StatusInfo *info = g_malloc0(sizeof(*info));
+    StatusInfo *info = g_new0(StatusInfo, 1);
 
     info->running = runstate_is_running();
     info->singlestep = singlestep;
@@ -1958,7 +1958,7 @@ static void add_device_config(int type, const char 
*cmdline)
 {
     struct device_config *conf;
 
-    conf = g_malloc0(sizeof(*conf));
+    conf = g_new0(struct device_config, 1);
     conf->type = type;
     conf->cmdline = cmdline;
     QTAILQ_INSERT_TAIL(&device_configs, conf, next);
diff --git a/xen-all.c b/xen-all.c
index b5e28ab..d0988c9 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -140,7 +140,7 @@ static void xen_ram_init(ram_addr_t ram_size)
     RAMBlock *new_block;
     ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
 
-    new_block = g_malloc0(sizeof (*new_block));
+    new_block = g_new0(RAMBlock, 1);
     pstrcpy(new_block->idstr, sizeof (new_block->idstr), "xen.ram");
     new_block->host = NULL;
     new_block->offset = 0;
@@ -190,7 +190,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)
     trace_xen_ram_alloc(ram_addr, size);
 
     nr_pfn = size >> TARGET_PAGE_BITS;
-    pfn_list = g_malloc(sizeof (*pfn_list) * nr_pfn);
+    pfn_list = g_new(xen_pfn_t, nr_pfn);
 
     for (i = 0; i < nr_pfn; i++) {
         pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i;
-- 
1.7.4.1




reply via email to

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