From patchwork Mon Sep 9 02:57:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 273471 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C2D722C0126 for ; Mon, 9 Sep 2013 12:59:17 +1000 (EST) Received: from localhost ([::1]:47387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrh5-0005fr-M3 for incoming@patchwork.ozlabs.org; Sun, 08 Sep 2013 22:59:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgQ-0005V1-Jz for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VIrgC-0000iO-O5 for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:34 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:47659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgC-0000hN-1P for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:20 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Sep 2013 08:18:43 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 9 Sep 2013 08:18:42 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id A87B1E0053 for ; Mon, 9 Sep 2013 08:29:00 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r892w83M47186038 for ; Mon, 9 Sep 2013 08:28:10 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r892w9qD007885 for ; Mon, 9 Sep 2013 08:28:09 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r892w6dj007807; Mon, 9 Sep 2013 08:28:08 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 9 Sep 2013 10:57:56 +0800 Message-Id: <1378695482-29805-2-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1378695482-29805-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1378695482-29805-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13090902-4790-0000-0000-00000A35746D X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.1 Cc: kwolf@redhat.com, pbonzini@redhat.com, mreitz@redhat.com, Wenchao Xia , stefanha@gmail.com Subject: [Qemu-devel] [PATCH V3 1/7] qcow2: restore nb_snapshots when fail in snapshot creation 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 If it is not restored after qcow2_write_snapshots() fail, a core dump will happen in bdrv_close() since access of invalid pointer. Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake --- block/qcow2-snapshot.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index e7e6013..40393b2 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -331,7 +331,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) QCowSnapshot *new_snapshot_list = NULL; QCowSnapshot *old_snapshot_list = NULL; QCowSnapshot sn1, *sn = &sn1; - int i, ret; + int i, ret, old_snapshot_num = 0; uint64_t *l1_table = NULL; int64_t l1_table_offset; @@ -403,6 +403,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) memcpy(new_snapshot_list, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot)); old_snapshot_list = s->snapshots; + old_snapshot_num = s->nb_snapshots; } s->snapshots = new_snapshot_list; s->snapshots[s->nb_snapshots++] = *sn; @@ -411,6 +412,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) if (ret < 0) { g_free(s->snapshots); s->snapshots = old_snapshot_list; + s->nb_snapshots = old_snapshot_num; goto fail; }