From patchwork Fri Nov 27 16:35:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 39632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 531141007D7 for ; Sat, 28 Nov 2009 03:37:44 +1100 (EST) Received: from localhost ([127.0.0.1]:39432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NE3pF-0006nd-FK for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2009 11:37:41 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NE3oj-0006mQ-VY for qemu-devel@nongnu.org; Fri, 27 Nov 2009 11:37:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NE3of-0006iI-5G for qemu-devel@nongnu.org; Fri, 27 Nov 2009 11:37:09 -0500 Received: from [199.232.76.173] (port=45117 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NE3oe-0006hx-Uy for qemu-devel@nongnu.org; Fri, 27 Nov 2009 11:37:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32191) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NE3oe-0001o1-I0 for qemu-devel@nongnu.org; Fri, 27 Nov 2009 11:37:04 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nARGb21g027026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 27 Nov 2009 11:37:02 -0500 Received: from localhost.localdomain (vpn2-8-149.ams2.redhat.com [10.36.8.149]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nARGb0Gn027495; Fri, 27 Nov 2009 11:37:01 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 27 Nov 2009 17:35:55 +0100 Message-Id: <1259339755-11155-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] qcow2: Fix some more qemu_malloc fallout X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Oh joy... Signed-off-by: Kevin Wolf --- block/qcow2-refcount.c | 22 +++++++++++++++------- block/qcow2-snapshot.c | 7 ++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3026678..54b19f8 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -513,7 +513,11 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, l1_size2 = l1_size * sizeof(uint64_t); l1_allocated = 0; if (l1_table_offset != s->l1_table_offset) { - l1_table = qemu_mallocz(align_offset(l1_size2, 512)); + if (l1_size2 != 0) { + l1_table = qemu_mallocz(align_offset(l1_size2, 512)); + } else { + l1_table = NULL; + } l1_allocated = 1; if (bdrv_pread(s->hd, l1_table_offset, l1_table, l1_size2) != l1_size2) @@ -769,12 +773,16 @@ static int check_refcounts_l1(BlockDriverState *bs, l1_table_offset, l1_size2); /* Read L1 table entries from disk */ - l1_table = qemu_malloc(l1_size2); - if (bdrv_pread(s->hd, l1_table_offset, - l1_table, l1_size2) != l1_size2) - goto fail; - for(i = 0;i < l1_size; i++) - be64_to_cpus(&l1_table[i]); + if (l1_size2 == 0) { + l1_table = NULL; + } else { + l1_table = qemu_malloc(l1_size2); + if (bdrv_pread(s->hd, l1_table_offset, + l1_table, l1_size2) != l1_size2) + goto fail; + for(i = 0;i < l1_size; i++) + be64_to_cpus(&l1_table[i]); + } /* Do the actual checks */ for(i = 0; i < l1_size; i++) { diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 94cb838..d63c7e1 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -266,7 +266,12 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) sn->l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t)); sn->l1_size = s->l1_size; - l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); + if (s->l1_size != 0) { + l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); + } else { + l1_table = NULL; + } + for(i = 0; i < s->l1_size; i++) { l1_table[i] = cpu_to_be64(s->l1_table[i]); }