@@ -514,7 +514,7 @@ static void coroutine_fn backup_run(void *opaque)
qemu_co_rwlock_unlock(&job->flush_rwlock);
g_free(job->done_bitmap);
- data = g_malloc(sizeof(*data));
+ data = g_new(BackupCompleteData, 1);
data->ret = ret;
block_job_defer_to_main_loop(&job->common, backup_complete, data);
}
@@ -175,7 +175,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
}
/* Set attributes common for all actions */
- rule = g_malloc0(sizeof(*rule));
+ rule = g_new(struct BlkdebugRule, 1);
*rule = (struct BlkdebugRule) {
.event = event,
.action = d->action,
@@ -727,7 +727,7 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
return -ENOENT;
}
- rule = g_malloc(sizeof(*rule));
+ rule = g_new(struct BlkdebugRule, 1);
*rule = (struct BlkdebugRule) {
.event = blkdebug_event,
.action = ACTION_SUSPEND,
@@ -210,7 +210,7 @@ static void coroutine_fn commit_run(void *opaque)
out:
qemu_vfree(buf);
- data = g_malloc(sizeof(*data));
+ data = g_new(CommitCompleteData, 1);
data->ret = ret;
block_job_defer_to_main_loop(&s->common, commit_complete, data);
}
@@ -474,7 +474,7 @@ LinuxAioState *laio_init(void)
{
LinuxAioState *s;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(LinuxAioState, 1);
if (event_notifier_init(&s->e, false) < 0) {
goto out_free_state;
}
@@ -904,7 +904,7 @@ immediate_exit:
g_free(s->in_flight_bitmap);
bdrv_dirty_iter_free(s->dbi);
- data = g_malloc(sizeof(*data));
+ data = g_new(MirrorExitData, 1);
data->ret = ret;
if (need_drain) {
@@ -455,7 +455,7 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
{
BlockStats *s = NULL;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(BlockStats, 1);
s->stats = g_malloc0(sizeof(*s->stats));
if (!bs) {
@@ -503,7 +503,7 @@ BlockInfoList *qmp_query_block(Error **errp)
continue;
}
- info = g_malloc0(sizeof(*info));
+ info = g_new0(BlockInfoList, 1);
bdrv_query_info(blk, &info->value, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@@ -755,7 +755,7 @@ static void update_refcount_discard(BlockDriverState *bs,
}
}
- d = g_malloc(sizeof(*d));
+ d = g_new(Qcow2DiscardRegion, 1);
*d = (Qcow2DiscardRegion) {
.bs = bs,
.offset = offset,
@@ -2189,9 +2189,8 @@ write_refblocks:
reftable_size = ROUND_UP((refblock_index + 1) * sizeof(uint64_t),
s->cluster_size) / sizeof(uint64_t);
- new_on_disk_reftable = g_try_realloc(on_disk_reftable,
- reftable_size *
- sizeof(uint64_t));
+ new_on_disk_reftable = g_try_renew(uint64_t, on_disk_reftable,
+ reftable_size);
if (!new_on_disk_reftable) {
res->check_errors++;
ret = -ENOMEM;
@@ -2656,8 +2655,7 @@ static int alloc_refblock(BlockDriverState *bs, uint64_t **reftable,
return -ENOTSUP;
}
- new_reftable = g_try_realloc(*reftable, new_reftable_size *
- sizeof(uint64_t));
+ new_reftable = g_try_renew(uint64_t, *reftable, new_reftable_size);
if (!new_reftable) {
error_setg(errp, "Failed to increase reftable buffer size");
return -ENOMEM;
@@ -3119,7 +3117,7 @@ int qcow2_shrink_reftable(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
uint64_t *reftable_tmp =
- g_malloc(s->refcount_table_size * sizeof(uint64_t));
+ g_new(uint64_t, s->refcount_table_size);
int i, ret;
for (i = 0; i < s->refcount_table_size; i++) {
@@ -90,7 +90,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);
@@ -467,7 +467,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;
@@ -202,7 +202,7 @@ static void coroutine_fn stream_run(void *opaque)
out:
/* Modify backing chain and close BDSes in main loop */
- data = g_malloc(sizeof(*data));
+ data = g_new(StreamCompleteData, 1);
data->ret = ret;
block_job_defer_to_main_loop(&s->common, stream_complete, data);
}
@@ -244,7 +244,7 @@ static void vhdx_region_register(BDRVVHDXState *s,
{
VHDXRegionEntry *r;
- r = g_malloc0(sizeof(*r));
+ r = g_new0(VHDXRegionEntry, 1);
r->start = start;
r->end = start + length;
@@ -190,7 +190,7 @@ QEMUWin32AIOState *win32_aio_init(void)
{
QEMUWin32AIOState *s;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(QEMUWin32AIOState, 1);
if (event_notifier_init(&s->e, false) < 0) {
goto out_free_state;
}
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- block/backup.c | 2 +- block/blkdebug.c | 4 ++-- block/commit.c | 2 +- block/linux-aio.c | 2 +- block/mirror.c | 2 +- block/qapi.c | 4 ++-- block/qcow2-refcount.c | 12 +++++------- block/qed-l2-cache.c | 2 +- block/sheepdog.c | 2 +- block/stream.c | 2 +- block/vhdx.c | 2 +- block/win32-aio.c | 2 +- 12 files changed, 18 insertions(+), 20 deletions(-)