From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwV2L-0002Z6-De for qemu-devel@nongnu.org; Mon, 16 Jun 2014 07:25:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwV2G-0001dZ-2S for qemu-devel@nongnu.org; Mon, 16 Jun 2014 07:25:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5345) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwV2F-0001dU-R2 for qemu-devel@nongnu.org; Mon, 16 Jun 2014 07:25:12 -0400 From: Stefan Hajnoczi Date: Mon, 16 Jun 2014 19:23:30 +0800 Message-Id: <1402917843-6459-7-git-send-email-stefanha@redhat.com> In-Reply-To: <1402917843-6459-1-git-send-email-stefanha@redhat.com> References: <1402917843-6459-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 06/39] block/nfs: fix potential segfault on early callback List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Peter Lieven , Stefan Hajnoczi From: Peter Lieven it will happen in the future that the callback of a libnfs call directly invokes the callback. In this case we end up in a segfault because the NFSRPC is gone when we the BH is scheduled. Signed-off-by: Peter Lieven Signed-off-by: Stefan Hajnoczi --- block/nfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/nfs.c b/block/nfs.c index bd9177f..e282f8d 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -95,6 +95,7 @@ static void nfs_co_init_task(NFSClient *client, NFSRPC *task) static void nfs_co_generic_bh_cb(void *opaque) { NFSRPC *task = opaque; + task->complete = 1; qemu_bh_delete(task->bh); qemu_coroutine_enter(task->co, NULL); } @@ -104,7 +105,6 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, void *private_data) { NFSRPC *task = private_data; - task->complete = 1; task->ret = ret; if (task->ret > 0 && task->iov) { if (task->ret <= task->iov->size) { @@ -123,6 +123,8 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, task->bh = aio_bh_new(task->client->aio_context, nfs_co_generic_bh_cb, task); qemu_bh_schedule(task->bh); + } else { + task->complete = 1; } } -- 1.9.3