xfs-masters
[Top] [All Lists]

[xfs-masters] Re: [RFC][PATCH] XFS: memory leak in xfs_inactive() - is x

To: David Chinner <dgc@xxxxxxx>
Subject: [xfs-masters] Re: [RFC][PATCH] XFS: memory leak in xfs_inactive() - is xfs_trans_free() enough or do we need xfs_trans_cancel() ?
From: Jesper Juhl <jesper.juhl@xxxxxxxxx>
Date: Fri, 18 May 2007 00:53:55 +0200
Cc: xfs-masters@xxxxxxxxxxx, xfs@xxxxxxxxxxx, Linux Kernel Mailing List <linux-kernel@xxxxxxxxxxxxxxx>, Jesper Juhl <jesper.juhl@xxxxxxxxx>
Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:from:to:subject:date:user-agent:cc:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=Y74CrE5kKcab9OvEfW8WvalROq7HckxOxCQ7BiZnxc2qXzlRJH2Hm3V696OWRBak2TfHDWD8xzpOtFDP9PZxFMFL1ntRor9jmywhUNYoWRVbQLTO0M6Ec3wM3LK0//jSk+dthlzgW8w1pIso58OhHZFYjLbF8vUds+RYd+kTDQc=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:from:to:subject:date:user-agent:cc:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=q+Ee5akpQ8pJsXKIoUmkzn5UI59+O8YmVEjZEg9vitrI52rQraEKdniq7J54xT3NOc8O22I8I1RFxp/8OWZiLYwhUp7F7SXqkDq01KBz0MRLbJ2zUb1wEu3Gm3D5uCNxwg7IMoLwO38Dky4DcotAeqeFKan7UyIhzrqPTBsRtp4=
In-reply-to: <20070517024024.GT85884050@xxxxxxx>
References: <200705162331.16429.jesper.juhl@xxxxxxxxx> <20070517024024.GT85884050@xxxxxxx>
Reply-to: xfs-masters@xxxxxxxxxxx
Sender: xfs-masters-bounce@xxxxxxxxxxx
User-agent: KMail/1.9.6
On Thursday 17 May 2007 04:40:24 David Chinner wrote:
> On Wed, May 16, 2007 at 11:31:16PM +0200, Jesper Juhl wrote:
> > Hi,
> > 
> > The Coverity checker found a memory leak in xfs_inactive().
> ....
> > So, the code allocates a transaction, but in the case where 'truncate' is
> > !=0 and xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE, 0); happens to return
> > an error, we'll just return from the function without dealing with the
> > memory allocated byxfs_trans_alloc() and assigned to 'tp', thus it'll be
> > orphaned/leaked - not good.
> 
> Yeah, introduced by:
> 
> http://git2.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d3cf209476b72c83907a412b6708c5e498410aa7
> 
> Thanks for reporting the problem, Jesper.
> 
You are welcome.

That commit introduces the same problem in xfs_inactive_free_eofblocks(). 
Patch to fix it below.

> > What I'm wondering is this; is it enough, at this point, to call
> > xfs_trans_free(tp); (it would seem to me that would be OK, but I'm not
> > intimite with this code) or do we need a full xfs_trans_cancel(tp, 0);  ???
> 
> xfs_trans_free() is not supposed to be called by anything but the transaction
> code (it's static). So a xfs_trans_cancel() would need to be issued.
> 
Makes sense. Thanks. I completely missed the static nature :-/



Fix XFS memory leak; allocated transaction not freed in 
xfs_inactive_free_eofblocks() in failure case.

Signed-off-by: Jesper Juhl <jesper.juhl@xxxxxxxxx>
--- 
 fs/xfs/xfs_vnodeops.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index de17aed..32519cf 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -1260,6 +1260,7 @@ xfs_inactive_free_eofblocks(
                error = xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE,
                                    ip->i_size);
                if (error) {
+                       xfs_trans_cancel(tp, 0);
                        xfs_iunlock(ip, XFS_IOLOCK_EXCL);
                        return error;
                }



<Prev in Thread] Current Thread [Next in Thread>