gfs2: Fix error path kobject memory leak
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: Fix error path kobject memory leak
From: "Tobin C. Harding" <[email protected]>
If a call to kobject_init_and_add() fails we must call kobject_put() otherwise we leak memory.
Function gfs2_sys_fs_add always calls kobject_init_and_add() which always calls kobject_init().
It is safe to leave object destruction up to the kobject release function and never free it manually.
Remove call to kfree() and always call kobject_put() in the error path.
--- fs/gfs2/sys.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
fs/gfs2/sys.c +1 -7
@@ -650,7 +650,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)char ro[20 ];char spectator[20 ];char *envp[] = { ro, spectator,NULL }; -int sysfs_frees_sdp =0 ;sprintf (ro,"RDONLY=%d" ,sb_rdonly (sb));sprintf (spectator,"SPECTATOR=%d" , sdp->sd_args.ar_spectator ?1 :0 );
@@ -661,8 +660,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)if (error) goto fail_reg; - sysfs_frees_sdp =1 ;/* Freeing sdp is now done by sysfs calling -function gfs2_sbd_release. */ error =sysfs_create_group (&sdp->sd_kobj, &tune_group);if (error) goto fail_reg;
@@ -687,10 +684,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp) fail_reg:free_percpu (sdp->sd_lkstats);fs_err (sdp,"error %d adding sysfs files\n" , error); -if (sysfs_frees_sdp) -kobject_put (&sdp->sd_kobj); -else -kfree (sdp); +kobject_put (&sdp->sd_kobj); sb->s_fs_info =NULL ;return error; }
Signature · 1 line
2.20.1
Andreas,
did you intend for me to take this as a patch from the email, or will
I get a pull request with this later?
Linus
Andreas Gruenbacher
maintainerQuoted 3 lines · Linus Torvalds
Andreas,
did you intend for me to take this as a patch from the email, or will
I get a pull request with this later?
Sorry, I should have been more explicit. Would you mind taking this patch, please? If it's more convenient or more appropriate, I'll send a pull request instead.
Thanks,
Andreas
Quoted 4 lines · Andreas Gruenbacher
Sorry, I should have been more explicit. Would you mind taking this patch, please? If it's more convenient or more appropriate, I'll send a pull request instead.
Done.
However,I'd like to point out that when I see patches from people who I normally get a pull request from, I usually ignore them.
Particularly when they are in some thread with discussion, I'll often just assume that th epatch is part of the thread, not really meant for me in particular.
In this case I happened to notice that suddenly my participation status changed, which is why I asked, but in general I might hav ejust archived the thread with the assumption that I'll be getting the patch later as a git pull.
Just so you'll be aware of this in the future, in case I don't react...
Linus
Andreas Gruenbacher
maintainerQuoted 15 lines · Linus Torvalds
Quoted 4 lines · Andreas Gruenbacher
Sorry, I should have been more explicit. Would you mind taking this patch, please? If it's more convenient or more appropriate, I'll send a pull request instead.
Done.
However, I'd like to point out that when I see patches from people who I normally get a pull request from, I usually ignore them.
Particularly when they are in some thread with discussion, I'll often just assume that the patch is part of the thread, not really meant for me in particular.
Quoted 6 lines
In this case I happened to notice that suddenly my participation status changed, which is why I asked, but in general I might have just archived the thread with the assumption that I'll be getting the patch later as a git pull.
Just so you'll be aware of this in the future, in case I don't react...
Thanks.
Copying Jon because this looks like useful information for other maintainers as well.
Andreas