mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC][PATCH] XFS: memory leak in xfs_inactive() - is xfs_trans_free() enough or do we need xfs_trans_cancel() ?
@ 2007-05-16 21:31 Jesper Juhl
  2007-05-17  2:40 ` David Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2007-05-16 21:31 UTC (permalink / raw)
  To: xfs-masters; +Cc: xfs, Linux Kernel Mailing List, Jesper Juhl

Hi,

The Coverity checker found a memory leak in xfs_inactive().

The offending code is this bit : 

1671 		tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE);

At conditional (1): "truncate != 0" taking true path

1672 		if (truncate) {
1673 			/*
1674 			 * Do the xfs_itruncate_start() call before
1675 			 * reserving any log space because itruncate_start
1676 			 * will call into the buffer cache and we can't
1677 			 * do that within a transaction.
1678 			 */
1679 			xfs_ilock(ip, XFS_IOLOCK_EXCL);
1680 	
1681 			error = xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE, 0);

At conditional (2): "error != 0" taking true path

1682 			if (error) {
1683 				xfs_iunlock(ip, XFS_IOLOCK_EXCL);

Event leaked_storage: Returned without freeing storage "tp"
Also see events: [alloc_fn][var_assign]

1684 				return VN_INACTIVE_CACHE;
1685 			}

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.

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);  ???

In case I'm right and xfs_trans_free(tp); is all we need, then please consider the patch below. Otherwise please NACK the patch and I'll cook up another one :-)


Fix memory leak on error in xfs_inactive().

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
--- 
 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..e0d3d51 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -1681,6 +1681,7 @@ xfs_inactive(
 		error = xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE, 0);
 		if (error) {
 			xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+			xfs_trans_free(tp);
 			return VN_INACTIVE_CACHE;
 		}
 


-- 
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-05-24 12:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-16 21:31 [RFC][PATCH] XFS: memory leak in xfs_inactive() - is xfs_trans_free() enough or do we need xfs_trans_cancel() ? Jesper Juhl
2007-05-17  2:40 ` David Chinner
2007-05-17 22:53   ` Jesper Juhl
2007-05-24 12:03     ` Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome