From patchwork Wed Oct 12 12:56:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 681185 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3svDRN0rmFz9t1q for ; Wed, 12 Oct 2016 23:57:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=hhSPT5hO; dkim-atps=neutral Received: from localhost ([::1]:33407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buJ6A-0002Yk-M6 for incoming@patchwork.ozlabs.org; Wed, 12 Oct 2016 08:57:30 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date; bh=LczB3cxyAHWTtDcJgovi41gla6pvuO1XvXcpRVA/oSk=; b=hhSPT5hOPaP80WVNGuFY6wtTQiWlsRw6cAXs3Z4jg+DdwbbJug5TJYG6vAJGneVYor wHfQH0nRtBhFcbIHNIOs8lmkyAMpUlVtkIGxmc6UQ0iLcswhcHU68/nu5+/mZCGQ5ntQ CL7GzNw0Z2/BYRK3uxtzvCpo+ynK1CW/sCInBWIHb/Cnpx3vlBhwl4XKMetEjabXIWaJ ERo4sRH6TkQ7XHFCeIAMFHmye0kP4LJJeoXE0vgERxsGull629O2N0nYfYfMYxYtsbUV rAoNWalZmUJL5E6cu/KdPUmFXhgeLl4W2sGdq5IK7tRpGpz77IU208mGAJTExXRV8ERi dMMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=LczB3cxyAHWTtDcJgovi41gla6pvuO1XvXcpRVA/oSk=; b=B8t20zOfkKhhrygTcy+4zWiqPsfcjehoSknC8BcVyVKiRNtQE8OEi90EMNUxbngnb+ QamTLvB2686BMTc8SgH372UGXVer2kzpan7EWaeWn/+cYigHQeAPYr6EfmhyNS8Af8aY JUIbalAZun7vapMPgF2fVMQtAQJTq/T6QmgUBbY8oEedgUqObl/4xBfg0u1aCL9gSOaQ KeqWy/p5tfv19FVmmVicxlsdeo9QnzeNrZTcKxfY6611OGbDsGbv/BUC+wiwhrd0x/4Q UtP89lhrDFvlqEMm3czctTsDhE16PK0ujuq42axcpRVog1UHTaRMqzptlzC9MXkwUNZK 576Q== X-Gm-Message-State: AA6/9RmC2EqVxk4R8ZEzXcD004JKn+LS5aE+XZq00R720VaGg0EtuOFgF9dNmMgcfV5KYw== X-Received: by 10.107.175.93 with SMTP id y90mr1248087ioe.86.1476277004311; Wed, 12 Oct 2016 05:56:44 -0700 (PDT) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id r67sm10812788itd.5.2016.10.12.05.56.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Oct 2016 05:56:43 -0700 (PDT) Message-ID: <57fe330b.4685240a.25d2d.b26c@mx.google.com> X-Google-Original-Message-ID: <1476276997-7468-1-git-send-email-Qiang(liqiang6-s@360.cn)> From: Li Qiang X-Google-Original-From: Li Qiang(liqiang6-s@360.cn) To: groug@kaod.org, qemu-devel@nongnu.org Date: Wed, 12 Oct 2016 05:56:37 -0700 X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::243 Subject: [Qemu-devel] [PATCH] 9pfs: fix memory leak in v9fs_write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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);