From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=48209 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUKoG-0003OU-Dv for qemu-devel@nongnu.org; Thu, 01 Jul 2010 10:32:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OUKoA-0008De-CJ for qemu-devel@nongnu.org; Thu, 01 Jul 2010 10:32:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26550) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OUKoA-0008DM-5g for qemu-devel@nongnu.org; Thu, 01 Jul 2010 10:32:06 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o61EW5BD004401 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 1 Jul 2010 10:32:05 -0400 From: Kevin Wolf Date: Thu, 1 Jul 2010 16:31:57 +0200 Message-Id: <1277994718-14443-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1277994718-14443-1-git-send-email-kwolf@redhat.com> References: <1277994718-14443-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] block: Fix too early free in multiwrite List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com bdrv_aio_writev may call the callback immediately (and it will commonly do so in error cases). If num_requests doesn't have its final value yet, multiwrite_cb will falsely detect that all requests are completed and frees the mcb. However, the mcb is still used by other requests that are started only afterwards. When all requests are completed, it is freed for the second time. Fix this by setting the right num_requests from the beginning. Signed-off-by: Kevin Wolf --- block.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index c40dd2c..9719649 100644 --- a/block.c +++ b/block.c @@ -2198,6 +2198,7 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs) num_reqs = multiwrite_merge(bs, reqs, num_reqs, mcb); // Run the aio requests + mcb->num_requests = num_reqs; for (i = 0; i < num_reqs; i++) { acb = bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov, reqs[i].nb_sectors, multiwrite_cb, mcb); @@ -2206,16 +2207,13 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs) // We can only fail the whole thing if no request has been // submitted yet. Otherwise we'll wait for the submitted AIOs to // complete and report the error in the callback. - if (mcb->num_requests == 0) { + if (i == 0) { reqs[i].error = -EIO; goto fail; } else { - mcb->num_requests++; multiwrite_cb(mcb, -EIO); break; } - } else { - mcb->num_requests++; } } -- 1.6.6.1