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: 9372681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EF6E460487 for ; Wed, 12 Oct 2016 12:57:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDDC728450 for ; Wed, 12 Oct 2016 12:57:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D23F529577; Wed, 12 Oct 2016 12:57:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3664228450 for ; Wed, 12 Oct 2016 12:57:08 +0000 (UTC) Received: from localhost ([::1]:33404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buJ5n-0002EV-09 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Oct 2016 08:57:07 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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);