From patchwork Fri Aug 15 17:07:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 380391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 77BD9140093 for ; Sat, 16 Aug 2014 03:35:04 +1000 (EST) Received: from localhost ([::1]:60868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XILP3-00053v-J4 for incoming@patchwork.ozlabs.org; Fri, 15 Aug 2014 13:35:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIL02-0008Pu-HY for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIKzw-0000Zx-Cl for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:09:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIKzw-0000Zs-59 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:09:04 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7FH92sC011964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Aug 2014 13:09:02 -0400 Received: from localhost (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7FH9167024920; Fri, 15 Aug 2014 13:09:01 -0400 From: Stefan Hajnoczi To: Date: Fri, 15 Aug 2014 18:07:02 +0100 Message-Id: <1408122422-13935-56-git-send-email-stefanha@redhat.com> In-Reply-To: <1408122422-13935-1-git-send-email-stefanha@redhat.com> References: <1408122422-13935-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 55/55] qcow2: fix new_blocks double-free in alloc_refcount_block() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Commit de82815db1c89da058b7fb941dab137d6d9ab738 ("qcow2: Handle failure for potentially large allocations") introduced a double-free of new_blocks in the alloc_refcount_block() error path. The qemu-iotests qcow2 026 test case was failing because qemu-io segfaulted. Make sure new_blocks is NULL after we free it the first time. Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- block/qcow2-refcount.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index d60e2fe..3b77470 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -381,6 +381,7 @@ static int alloc_refcount_block(BlockDriverState *bs, ret = bdrv_pwrite_sync(bs->file, meta_offset, new_blocks, blocks_clusters * s->cluster_size); g_free(new_blocks); + new_blocks = NULL; if (ret < 0) { goto fail_table; }