From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 2/4] qcow2: Use g_try_new0() for cache array
Date: Mon, 18 Aug 2014 22:00:27 +0200 [thread overview]
Message-ID: <1408392029-29531-3-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1408392029-29531-1-git-send-email-mreitz@redhat.com>
With a variable cache size, the number given to qcow2_cache_create() may
be huge. Therefore, use g_try_new0().
While at it, use g_new0() instead of g_malloc0() for allocating the
Qcow2Cache object.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/qcow2-cache.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index fe0615a..6eabfaa 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -48,9 +48,12 @@ 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_new0(Qcow2CachedTable, num_tables);
+ c->entries = g_try_new0(Qcow2CachedTable, num_tables);
+ if (!c->entries) {
+ goto fail;
+ }
for (i = 0; i < c->size; i++) {
c->entries[i].table = qemu_try_blockalign(bs->file, s->cluster_size);
--
2.0.4
next prev parent reply other threads:[~2014-08-18 20:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-18 20:00 [Qemu-devel] [PATCH 0/4] qcow2: Allow runtime specification of cache sizes Max Reitz
2014-08-18 20:00 ` [Qemu-devel] [PATCH 1/4] qcow2: Constant cache size in bytes Max Reitz
2014-08-18 20:00 ` Max Reitz [this message]
2014-08-18 20:01 ` [Qemu-devel] [PATCH 2/4] qcow2: Use g_try_new0() for cache array Max Reitz
2014-08-18 20:00 ` [Qemu-devel] [PATCH 3/4] qcow2: Add runtime options for cache sizes Max Reitz
2014-08-18 20:18 ` Eric Blake
2014-08-18 20:24 ` Max Reitz
2014-08-18 20:25 ` Max Reitz
2014-08-18 20:00 ` [Qemu-devel] [PATCH 4/4] iotests: Add test for qcow2's cache options Max Reitz
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=1408392029-29531-3-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).