Skip to contentSkip to conversation

xfs: fix memory leak in xlog_recover_add_to_trans

PATCH Applied [email protected] 3 participants 6 messages Sep 27, 2013 – Oct 1, 2013 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix memory leak in xlog_recover_add_to_trans

Free the memory in error path of xlog_recover_add_to_trans(). Normally this memory is freed in recovery pass2, but is leaked in the error path.

---
Found by Coverity (134683) in userspace, same patch applies there also.

 fs/xfs/xfs_log_recover.c |    1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_log_recover.c +1 -0
Index: b/fs/xfs/xfs_log_recover.c
===================================================================
@@ -1585,6 +1585,7 @@ xlog_recover_add_to_trans(
 		"bad number of regions (%d) in inode log format",
 				  in_f->ilf_size);
 			ASSERT(0);
+			free(ptr);
 			return XFS_ERROR(EIO);
 		}
 

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On 9/27/13 9:00 AM, [email protected] wrote:

Free the memory in error path of xlog_recover_add_to_trans(). Normally this memory is freed in recovery pass2, but is leaked in the error path.

For this local leak & the fix,

Since this gets called in a loop from xlog_recover_process_data(), I'm wondering what happens to previously-allocated items, if we return an error and never get to pass2?

(I could be off base, haven't really followed it through, but it seems like they might leak).

Thanks,
-Eric

Quoted 20 lines

---
Found by Coverity (134683) in userspace, same patch applies there also.

 fs/xfs/xfs_log_recover.c |    1 +
 1 file changed, 1 insertion(+)

Index: b/fs/xfs/xfs_log_recover.c
===================================================================

fs/xfs/xfs_log_recover.c +1 -0
@@ -1585,6 +1585,7 @@ xlog_recover_add_to_trans(
 		"bad number of regions (%d) in inode log format",
 				  in_f->ilf_size);
 			ASSERT(0);
+			free(ptr);
 			return XFS_ERROR(EIO);
 		}
 
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

#2 lore raw
Quoted 15 lines · Eric Sandeen
Quoted 5 lines · On 9/27/13 9:00 AM, [email protected] wrote:

Free the memory in error path of xlog_recover_add_to_trans(). Normally this memory is freed in recovery pass2, but is leaked in the error path.

For this local leak & the fix,

Since this gets called in a loop from xlog_recover_process_data(), I'm wondering what happens to previously-allocated items, if we return an error and never get to pass2?

Quoted 5 lines

(I could be off base, haven't really followed it through, but it seems like they might leak).

Thanks,
-Eric

yeah you are correct, it looks like it gets leaked. I will add it to the list.

Thanks.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 16 lines · Mark Tinguely
Quoted 15 lines · Eric Sandeen
Quoted 5 lines · On 9/27/13 9:00 AM, [email protected] wrote:

Free the memory in error path of xlog_recover_add_to_trans(). Normally this memory is freed in recovery pass2, but is leaked in the error path.

For this local leak & the fix,

Since this gets called in a loop from xlog_recover_process_data(), I'm wondering what happens to previously-allocated items, if we return an error and never get to pass2?

Quoted 8 lines
Quoted 5 lines

(I could be off base, haven't really followed it through, but it seems like they might leak).

Thanks,
-Eric

yeah you are correct, it looks like it gets leaked. I will add it to the list.

Thanks. I suppose maybe if it's cleaned up at a higher level, it doesn't need to be done here, but (*shrug*) I'll let you work that out. :)

-Eric

Quoted 4 lines

Thanks.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw
Quoted 8 lines · Ben Myers
Quoted 5 lines · On Fri, Sep 27, 2013 at 09:00:55AM -0500, [email protected] wrote:

Free the memory in error path of xlog_recover_add_to_trans(). Normally this memory is freed in recovery pass2, but is leaked in the error path.

Applied.

fs/xfs/xfs_log_recover.c +1 -0
Index: b/fs/xfs/xfs_log_recover.c
===================================================================
@@ -1585,6 +1585,7 @@ xlog_recover_add_to_trans(
 		"bad number of regions (%d) in inode log format",
 				  in_f->ilf_size);
 			ASSERT(0);
+			free(ptr);
 

Sigh. I am a big fat, dunce-hatted, dork. This is the xfsprogs patch. The kernel needs kmem_free().

Please pull the patch. I will redo the whole thing to also make sure the list is removed on error.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs