From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWXP-0005Gk-Ru for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:06:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btWXK-00028q-3d for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:06:23 -0400 Received: from 10.mo6.mail-out.ovh.net ([87.98.157.236]:41311) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btWXJ-00028b-U6 for qemu-devel@nongnu.org; Mon, 10 Oct 2016 05:06:18 -0400 Received: from player738.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 1AC3D3CC68 for ; Mon, 10 Oct 2016 11:06:17 +0200 (CEST) Date: Mon, 10 Oct 2016 11:06:11 +0200 From: Greg Kurz Message-ID: <20161010110611.385ef476@bahia> In-Reply-To: <648301670b2dc88aec68e48abd1bef07c1e201a3.1475990063.git.liqiang6-s@360.cn> References: <648301670b2dc88aec68e48abd1bef07c1e201a3.1475990063.git.liqiang6-s@360.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] 9pfs: fix memory leak about xattr value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Li Qiang Cc: qemu-devel@nongnu.org, Li Qiang On Sat, 8 Oct 2016 22:27:08 -0700 Li Qiang wrote: > 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. > This cannot happen because v9fs_xattrwalk() always allocates this fid: xattr_fidp = alloc_fid(s, newfid); if (xattr_fidp == NULL) { err = -EINVAL; goto out; } > 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);