From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 From: Wenchao Xia Date: Mon, 9 Sep 2013 10:57:56 +0800 Message-Id: <1378695482-29805-2-git-send-email-xiawenc@linux.vnet.ibm.com> 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> Subject: [Qemu-devel] [PATCH V3 1/7] qcow2: restore nb_snapshots when fail in snapshot creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, mreitz@redhat.com, Wenchao Xia , stefanha@gmail.com 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 --- 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; } -- 1.7.1