From patchwork Sun Oct 9 05:27:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 679994 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 3ssBcP73TWz9ryv for ; Sun, 9 Oct 2016 16:28:21 +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=gDhO8nMq; dkim-atps=neutral Received: from localhost ([::1]:43165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bt6eo-0006ho-SN for incoming@patchwork.ozlabs.org; Sun, 09 Oct 2016 01:28:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bt6ds-00066D-Ex for qemu-devel@nongnu.org; Sun, 09 Oct 2016 01:27:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bt6dq-0005BA-Dk for qemu-devel@nongnu.org; Sun, 09 Oct 2016 01:27:19 -0400 Received: from mail-yb0-x244.google.com ([2607:f8b0:4002:c09::244]:34487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bt6dq-0005B5-9t for qemu-devel@nongnu.org; Sun, 09 Oct 2016 01:27:18 -0400 Received: by mail-yb0-x244.google.com with SMTP id 191so1880937ybv.1 for ; Sat, 08 Oct 2016 22:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z4fCP8jU9tX6HIJs4DLTTE+VtfbLayK4OmWEDGpqHtQ=; b=gDhO8nMqDtL0ZfFQOuXOoIuzEXOYx+uvYatPWlgS6vjFN2INeJMr/46gSj2O+imo23 8Oshq7hqvFMRN1AL5womMFAuvpyLYwSAKJgxadcj2FceQ8fbTyAWegss2rcn+usL7npD BjgXcaL3rhQ4j6QGZgje1DmZy4aTl+XF5Wp917vhSfQ2akWfsxUcgSMgPA6NmzA30vI3 0A4cGots2DF0AyqCTUfo/iPIdMVoVd25Q0eEEur6z1/EpuR+rYXq8xM4ZNgttccw2neQ ZIzuPaAHh9YfDr0JMjTOzTa9Racac+QsSdws4hNV2u9uhUpSimHOYk+wAz6/0xjCIKPD 2H7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z4fCP8jU9tX6HIJs4DLTTE+VtfbLayK4OmWEDGpqHtQ=; b=BlRHzMbTMgTuJgPIkHPvm9btLnBdqqKa5fKAfdiw7BeZvZNWVfcmHAwp4JjChEcK/L oq0BCUUOHS1bUhrtBSgBog7IV8nmbgvxoo5hQJA9MdKlHurBittS0JbiCaSfq2TMMKtS OW+P3RZOvIR5z6XehU4ufet2TR2VCF2pTqouEYmKW0g8kRjQi9t0HO2K3YKZrde2HPTD wimnTPwZ1ewJ5fxKtDm9j4qqYoIhGg4lA9614S1AS5Hy+5yFHS/riZCX0ajTGUOlIrxE C6AEv6b1oWPmFg1sztHNkBH1QSf0GlIKuUJOAo6OLZBUUpTeGDI3vD5nAfNiYpazhylt snHQ== X-Gm-Message-State: AA6/9Rl31/MxJRsofvqjqhyg2qZthU9qU9MpDPd3jtvACbKFQTDD7c1vMrHV1hKKeaUZqg== X-Received: by 10.37.197.19 with SMTP id v19mr23187055ybe.129.1475990837860; Sat, 08 Oct 2016 22:27:17 -0700 (PDT) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id k132sm5885317ywc.36.2016.10.08.22.27.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Oct 2016 22:27:17 -0700 (PDT) From: Li Qiang X-Google-Original-From: Li Qiang(liqiang6-s@360.cn) To: groug@kaod.org, qemu-devel@nongnu.org Date: Sat, 8 Oct 2016 22:27:08 -0700 Message-Id: <648301670b2dc88aec68e48abd1bef07c1e201a3.1475990063.git.liqiang6-s@360.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c09::244 Subject: [Qemu-devel] [PATCH 2/2] 9pfs: fix memory leak about xattr value 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 The 'fs.xattr.value' field in V9fsFidState object doesn't consider the situation that this field has been allocated previously. Every time, it will be allocated directly. This leads a host memory leak issue. This patch fix this. Signed-off-by: Li Qiang --- hw/9pfs/9p.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 8751c19..3af23f9 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -350,6 +350,7 @@ free_out: v9fs_string_free(&fidp->fs.xattr.name); free_value: g_free(fidp->fs.xattr.value); + fidp->fs.xattr.value = NULL; return retval; } @@ -3191,7 +3192,8 @@ static void v9fs_xattrwalk(void *opaque) xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.copied_len = -1; if (size) { - xattr_fidp->fs.xattr.value = g_malloc(size); + xattr_fidp->fs.xattr.value = g_realloc( + xattr_fidp->fs.xattr.value, size); err = v9fs_co_llistxattr(pdu, &xattr_fidp->path, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len); @@ -3224,7 +3226,8 @@ static void v9fs_xattrwalk(void *opaque) xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.copied_len = -1; if (size) { - xattr_fidp->fs.xattr.value = g_malloc(size); + xattr_fidp->fs.xattr.value = g_realloc( + xattr_fidp->fs.xattr.value, size); err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, &name, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len);