Received: from eggs.gnu.org ([2001:4830:134:3::10]:42711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buJ5V-0002EO-3h for qemu-devel@nongnu.org; Wed, 12 Oct 2016 08:56:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buJ5R-0004L6-0S for qemu-devel@nongnu.org; Wed, 12 Oct 2016 08:56:48 -0400 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]:33093) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buJ5Q-0004Kw-SU for qemu-devel@nongnu.org; Wed, 12 Oct 2016 08:56:44 -0400 Received: by mail-io0-x243.google.com with SMTP id q192so3016321iod.0 for ; Wed, 12 Oct 2016 05:56:44 -0700 (PDT) Message-ID: <57fe330b.4685240a.25d2d.b26c@mx.google.com> From: Li Qiang Date: Wed, 12 Oct 2016 05:56:37 -0700 Subject: [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_write List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: groug@kaod.org, qemu-devel@nongnu.org Cc: Li Qiang From: Li Qiang If an error occurs when marshal the transfer length to the guest, the v9fs_write doesn't free a IO vector, thus leading a memory leak. This patch fix this. Signed-off-by: Li Qiang --- fsdev/9p-iov-marshal.c | 2 +- hw/9pfs/9p.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsdev/9p-iov-marshal.c b/fsdev/9p-iov-marshal.c index 663cad5..1d16f8d 100644 --- a/fsdev/9p-iov-marshal.c +++ b/fsdev/9p-iov-marshal.c @@ -125,7 +125,7 @@ ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int out_num, size_t offset, str->data = g_malloc(str->size + 1); copied = v9fs_unpack(str->data, out_sg, out_num, offset, str->size); - if (copied > 0) { + if (copied >= 0) { str->data[str->size] = 0; } else { v9fs_string_free(str); diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 29f8b7a..76522e7 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2090,7 +2090,7 @@ static void v9fs_write(void *opaque) offset = 7; err = pdu_marshal(pdu, offset, "d", total); if (err < 0) { - goto out; + goto out_qiov; } err += offset; trace_v9fs_write_return(pdu->tag, pdu->id, total, err); -- 1.8.3.1