From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: [Qemu-devel] [PATCH v2 01/11] g_malloc(0) and g_malloc0(0) return NULL; simplify
Date: Wed, 16 Jan 2013 18:32:10 +0100 [thread overview]
Message-ID: <1358357540-29862-2-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1358357540-29862-1-git-send-email-armbru@redhat.com>
Once upon a time, it was decided that qemu_malloc(0) should abort.
Switching to glib retired that bright idea. Some code that was added
to cope with it (e.g. in commits 702ef63, b76b6e9) is still around.
Bury it.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
block/qcow2-refcount.c | 6 +-----
block/vdi.c | 4 +---
hw/9pfs/virtio-9p.c | 6 +-----
hw/vhost.c | 7 ++-----
4 files changed, 5 insertions(+), 18 deletions(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 6a95aa6..bc1784c 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -737,11 +737,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
* l1_table_offset when it is the current s->l1_table_offset! Be careful
* when changing this! */
if (l1_table_offset != s->l1_table_offset) {
- if (l1_size2 != 0) {
- l1_table = g_malloc0(align_offset(l1_size2, 512));
- } else {
- l1_table = NULL;
- }
+ l1_table = g_malloc0(align_offset(l1_size2, 512));
l1_allocated = 1;
if (bdrv_pread(bs->file, l1_table_offset,
l1_table, l1_size2) != l1_size2)
diff --git a/block/vdi.c b/block/vdi.c
index 021abaa..8dfefdb 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -429,9 +429,7 @@ static int vdi_open(BlockDriverState *bs, int flags)
bmap_size = header.blocks_in_image * sizeof(uint32_t);
bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE;
- if (bmap_size > 0) {
- s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
- }
+ s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
if (bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size) < 0) {
goto fail_free_bmap;
}
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0aaf0d2..b795839 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3101,11 +3101,7 @@ static void v9fs_xattrcreate(void *opaque)
xattr_fidp->fs.xattr.flags = flags;
v9fs_string_init(&xattr_fidp->fs.xattr.name);
v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
- if (size) {
- xattr_fidp->fs.xattr.value = g_malloc(size);
- } else {
- xattr_fidp->fs.xattr.value = NULL;
- }
+ xattr_fidp->fs.xattr.value = g_malloc(size);
err = offset;
put_fid(pdu, file_fidp);
out_nofid:
diff --git a/hw/vhost.c b/hw/vhost.c
index cee8aad..0dd2a9a 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -269,11 +269,8 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)
vhost_log_chunk_t *log;
uint64_t log_base;
int r, i;
- if (size) {
- log = g_malloc0(size * sizeof *log);
- } else {
- log = NULL;
- }
+
+ log = g_malloc0(size * sizeof *log);
log_base = (uint64_t)(unsigned long)log;
r = ioctl(dev->control, VHOST_SET_LOG_BASE, &log_base);
assert(r >= 0);
--
1.7.11.7
next prev parent reply other threads:[~2013-01-16 17:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 17:32 [Qemu-devel] Trivial memory allocation fixes & cleanups Markus Armbruster
2013-01-16 17:32 ` Markus Armbruster [this message]
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 02/11] g_strdup(NULL) returns NULL; simplify Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 03/11] hw/9pfs: Fix unchecked strdup() by converting to g_strdup() Markus Armbruster
2013-01-17 11:19 ` Stefan Hajnoczi
2013-01-17 13:21 ` Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 04/11] readline: " Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 05/11] spice: " Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 06/11] virtfs-proxy-helper: Fix unchecked strdup() by conv. " Markus Armbruster
2013-01-17 11:22 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
2013-01-17 13:10 ` Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 07/11] qemu-log: Fix unchecked strdup() by converting " Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 08/11] qemu-log: Plug trivial memory leak in cpu_set_log_filename() Markus Armbruster
2013-01-16 18:10 ` Eric Blake
2013-01-17 11:24 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
2013-01-17 13:17 ` Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 09/11] libcacard: Fix unchecked strdup() by converting to g_strdup() Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 10/11] qapi: " Markus Armbruster
2013-01-16 17:32 ` [Qemu-devel] [PATCH v2 11/11] qemu-ga: " Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1358357540-29862-2-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).