xfs: fix memory leak in xfs_dir2_node_removename
PATCH 1/1 xfs: fix memory leak in xfs_dir2_node_removename
Free the memory pointed to by state before returning on error from xfs_dir2_node_removename.c
---
Found by Coverity (134681) in userspace, same patch applies there also.
fs/xfs/xfs_dir2_node.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/xfs/xfs_dir2_node.c +5 -5
@@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(/* * Didn't find it, upper layer screwed up. */ -if (rval !=EEXIST ) { -xfs_da_state_free (state); -return rval; - } +if (rval !=EEXIST ) + goto done; + blk = &state->path.blk[state->path.active -1 ];ASSERT (blk->magic ==XFS_DIR2_LEAFN_MAGIC );ASSERT (state->extravalid);
@@ -2145,7 +2144,7 @@ xfs_dir2_node_removename( error =xfs_dir2_leafn_remove (args, blk->bp, blk->index, &state->extrablk, &rval);if (error) -return error; + goto done;/* * Fix the hash values up the btree. */
@@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(*/ if (!error) error =xfs_dir2_node_to_leaf (state); +done:xfs_da_state_free (state);return error; }
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Looks good,
Quoted 52 lines · Mark Tinguely
Free the memory pointed to by state before returning on error from
xfs_dir2_node_removename.cSigned-off-by Mark Tinguely <[email protected]>---
Found by Coverity (134681) in userspace, same patch applies there also.fs/xfs/xfs_dir2_node.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)Index:
b/fs/xfs/xfs_dir2_node.c
===================================================================fs/xfs/xfs_dir2_node.c +5
-5@@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(/* * Didn't find it, upper layer screwed up. */ -if (rval !=EEXIST ) { -xfs_da_state_free (state); -return rval; - } +if (rval !=EEXIST ) + goto done; + blk = &state->path.blk[state->path.active -1 ];ASSERT (blk->magic ==XFS_DIR2_LEAFN_MAGIC );ASSERT (state->extravalid);@@ -2145,7 +2144,7 @@ xfs_dir2_node_removename( error =xfs_dir2_leafn_remove (args, blk->bp, blk->index, &state->extrablk, &rval);if (error) -return error; + goto done;/* * Fix the hash values up the btree. */ @@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(*/ if (!error) error =xfs_dir2_node_to_leaf (state); +done:xfs_da_state_free (state);return error; }_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Signature · 6 lines
Carlos _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 7 lines · Mark Tinguely
Free the memory pointed to by state before returning on error from
xfs_dir2_node_removename.cSigned-off-by Mark Tinguely <[email protected]>---
Found by Coverity (134681) in userspace, same patch applies there also.
Heh, looks like that one has been around since the dawn of time, thanks.
how do we handle the matching userspace fixes, separate patch to be explicit? Wait for the next syncup?
Thanks,
-Eric
Quoted 40 lines
fs/xfs/xfs_dir2_node.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)Index:
b/fs/xfs/xfs_dir2_node.c
===================================================================fs/xfs/xfs_dir2_node.c +5
-5@@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(/* * Didn't find it, upper layer screwed up. */ -if (rval !=EEXIST ) { -xfs_da_state_free (state); -return rval; - } +if (rval !=EEXIST ) + goto done; + blk = &state->path.blk[state->path.active -1 ];ASSERT (blk->magic ==XFS_DIR2_LEAFN_MAGIC );ASSERT (state->extravalid);@@ -2145,7 +2144,7 @@ xfs_dir2_node_removename( error =xfs_dir2_leafn_remove (args, blk->bp, blk->index, &state->extrablk, &rval);if (error) -return error; + goto done;/* * Fix the hash values up the btree. */ @@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(*/ if (!error) error =xfs_dir2_node_to_leaf (state); +done:xfs_da_state_free (state);return error; }
Quoted 5 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 11 lines · Eric Sandeen
Quoted 7 lines · Mark Tinguely
Free the memory pointed to by state before returning on error from
xfs_dir2_node_removename.cSigned-off-by Mark Tinguely<[email protected]>---
Found by Coverity (134681) in userspace, same patch applies there also.Heh, looks like that one has been around since the dawn of time, thanks.
Quoted 7 lines
Reviewed-by Eric Sandeen<[email protected]>how do we handle the matching userspace fixes, separate patch to be explicit? Wait for the next syncup?
Thanks,
-Eric
<patch delete>
Good question.
The user space should be kept up to date with the kernel.
Since the patches will be identical except the directory name, I was hoping to submit one copy. But I am not trying to invent a policy, just being lazy.
--Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 22 lines · Mark Tinguely
Quoted 11 lines · Eric Sandeen
Quoted 7 lines · Mark Tinguely
Free the memory pointed to by state before returning on error from
xfs_dir2_node_removename.cSigned-off-by Mark Tinguely<[email protected]>---
Found by Coverity (134681) in userspace, same patch applies there also.Heh, looks like that one has been around since the dawn of time, thanks.
Quoted 7 lines
Reviewed-by Eric Sandeen<[email protected]>how do we handle the matching userspace fixes, separate patch to be explicit? Wait for the next syncup?
Thanks,
-Eric<patch delete>
Quoted 8 lines
Good question.
The user space should be kept up to date with the kernel.
Since the patches will be identical except the directory name, I was hoping to submit one copy. But I am not trying to invent a policy, just being lazy.
--Mark.
Was just an offhanded question; it'd just be good to know what we all expect.
I suppose that it could depend on the severity of the flaw; a minor leak before exit() isn't a big deal and could wait for a global sync-up; a data corruption fix might need to be quickly merged to both trees.
-Eric
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 10 lines · Mark Tinguely
plain text document attachment (xfs-fix-leak-in-xfs_dir2_node_removename.patch)
Free the memory pointed to by state before returning on error fromxfs_dir2_node_removename.cSigned-off-by Mark Tinguely <[email protected]>---
Found by Coverity (134681) in userspace, same patch applies there also.
Is the first hunk right ?
xfs_da_node_lookup_int called as
error = xfs_da_node_lookup_int(state, &rval);
and returns with
*result = retval;
return(0);so, on return, error == 0 and rval == an error code. The next lines:
if (error)
rval = error;won't change that. But previously if rval != EEXIST you returned rval. With the change below, you return error, which is zero.
--
Roger
Quoted 45 lines
fs/xfs/xfs_dir2_node.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)Index:
b/fs/xfs/xfs_dir2_node.c
===================================================================fs/xfs/xfs_dir2_node.c +5
-5@@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(/* * Didn't find it, upper layer screwed up. */ -if (rval !=EEXIST ) { -xfs_da_state_free (state); -return rval; - } +if (rval !=EEXIST ) + goto done; + blk = &state->path.blk[state->path.active -1 ];ASSERT (blk->magic ==XFS_DIR2_LEAFN_MAGIC );ASSERT (state->extravalid);@@ -2145,7 +2144,7 @@ xfs_dir2_node_removename( error =xfs_dir2_leafn_remove (args, blk->bp, blk->index, &state->extrablk, &rval);if (error) -return error; + goto done;/* * Fix the hash values up the btree. */ @@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(*/ if (!error) error =xfs_dir2_node_to_leaf (state); +done:xfs_da_state_free (state);return error; }_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Signature · 6 lines
Roger Willcocks <[email protected]> _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 26 lines · Roger Willcocks
Quoted 10 lines · Mark Tinguely
plain text document attachment (xfs-fix-leak-in-xfs_dir2_node_removename.patch)
Free the memory pointed to by state before returning on error fromxfs_dir2_node_removename.cSigned-off-by Mark Tinguely<[email protected]>---
Found by Coverity (134681) in userspace, same patch applies there also.Is the first hunk right ?
xfs_da_node_lookup_intcalled aserror = xfs_da_node_lookup_int(state,&rval);and returns with
*result = retval; return(0);so, on return, error == 0 and rval == an error code. The next lines:
Quoted 8 lines
if (error) rval = error;won't change that. But previously if rval != EEXIST you returned rval. With the change below, you return error, which is zero.
--
Roger
Thanks, guilty as charged. need to add the error = EEXIST.
--Mark.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 24 lines · Roger Willcocks
Quoted 10 lines · Mark Tinguely
plain text document attachment (xfs-fix-leak-in-xfs_dir2_node_removename.patch)
Free the memory pointed to by state before returning on error fromxfs_dir2_node_removename.cSigned-off-by Mark Tinguely <[email protected]>---
Found by Coverity (134681) in userspace, same patch applies there also.Is the first hunk right ?
xfs_da_node_lookup_intcalled aserror = xfs_da_node_lookup_int(state, &rval);and returns with
*result = retval; return(0);
Quoted 7 lines
so, on return, error == 0 and rval == an error code. The next lines:
if (error) rval = error;won't change that. But previously if rval != EEXIST you returned rval. With the change below, you return error, which is zero.
Oh geez. o_O . . . Thanks Roger.
3rd review's the charm? ;)
-Eric
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs