Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1642901 > unrolled thread

[PATCH 2/2] ubifs: Fix memory leak in RENAME_WHITEOUT error path in do_rename

Started byHyunchul Lee <cheol.lee@lge.com>
First post2017-05-17 02:10 +0200
Last post2017-05-17 09:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 2/2] ubifs: Fix memory leak in RENAME_WHITEOUT error path in do_rename Hyunchul Lee <cheol.lee@lge.com> - 2017-05-17 02:10 +0200
    Re: [PATCH 2/2] ubifs: Fix memory leak in RENAME_WHITEOUT error path  in do_rename Richard Weinberger <richard@nod.at> - 2017-05-17 09:10 +0200

#1642901 — [PATCH 2/2] ubifs: Fix memory leak in RENAME_WHITEOUT error path in do_rename

FromHyunchul Lee <cheol.lee@lge.com>
Date2017-05-17 02:10 +0200
Subject[PATCH 2/2] ubifs: Fix memory leak in RENAME_WHITEOUT error path in do_rename
Message-ID<tHUHn-4dm-7@gated-at.bofh.it>
in RENAME_WHITEOUT error path, fscrypt_name should be freed.

Signed-off-by: Hyunchul Lee <cheol.lee@lge.com>
---
 fs/ubifs/dir.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index df67236..0d5f8e7 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -1385,17 +1385,14 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
 
 		dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
 		if (!dev) {
-			ubifs_release_budget(c, &req);
-			ubifs_release_budget(c, &ino_req);
-			return -ENOMEM;
+			err = -ENOMEM;
+			goto out_release;
 		}
 
 		err = do_tmpfile(old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE, &whiteout);
 		if (err) {
-			ubifs_release_budget(c, &req);
-			ubifs_release_budget(c, &ino_req);
 			kfree(dev);
-			return err;
+			goto out_release;
 		}
 
 		whiteout->i_state |= I_LINKABLE;
@@ -1483,12 +1480,10 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
 
 		err = ubifs_budget_space(c, &wht_req);
 		if (err) {
-			ubifs_release_budget(c, &req);
-			ubifs_release_budget(c, &ino_req);
 			kfree(whiteout_ui->data);
 			whiteout_ui->data_len = 0;
 			iput(whiteout);
-			return err;
+			goto out_release;
 		}
 
 		inc_nlink(whiteout);
@@ -1543,6 +1538,7 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
 		iput(whiteout);
 	}
 	unlock_4_inodes(old_dir, new_dir, new_inode, whiteout);
+out_release:
 	ubifs_release_budget(c, &ino_req);
 	ubifs_release_budget(c, &req);
 	fscrypt_free_filename(&old_nm);
-- 
1.9.1

[toc] | [next] | [standalone]


#1643026 — Re: [PATCH 2/2] ubifs: Fix memory leak in RENAME_WHITEOUT error path in do_rename

FromRichard Weinberger <richard@nod.at>
Date2017-05-17 09:10 +0200
SubjectRe: [PATCH 2/2] ubifs: Fix memory leak in RENAME_WHITEOUT error path in do_rename
Message-ID<tI1fP-8p3-17@gated-at.bofh.it>
In reply to#1642901
Hyunchul,

Am 17.05.2017 um 01:58 schrieb Hyunchul Lee:
> in RENAME_WHITEOUT error path, fscrypt_name should be freed.
> 
> Signed-off-by: Hyunchul Lee <cheol.lee@lge.com>
> ---
>  fs/ubifs/dir.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
> index df67236..0d5f8e7 100644
> --- a/fs/ubifs/dir.c
> +++ b/fs/ubifs/dir.c
> @@ -1385,17 +1385,14 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
>  
>  		dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
>  		if (!dev) {
> -			ubifs_release_budget(c, &req);
> -			ubifs_release_budget(c, &ino_req);
> -			return -ENOMEM;
> +			err = -ENOMEM;
> +			goto out_release;
>  		}
>  
>  		err = do_tmpfile(old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE, &whiteout);
>  		if (err) {
> -			ubifs_release_budget(c, &req);
> -			ubifs_release_budget(c, &ino_req);
>  			kfree(dev);
> -			return err;
> +			goto out_release;
>  		}
>  
>  		whiteout->i_state |= I_LINKABLE;
> @@ -1483,12 +1480,10 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
>  
>  		err = ubifs_budget_space(c, &wht_req);
>  		if (err) {
> -			ubifs_release_budget(c, &req);
> -			ubifs_release_budget(c, &ino_req);
>  			kfree(whiteout_ui->data);
>  			whiteout_ui->data_len = 0;
>  			iput(whiteout);
> -			return err;
> +			goto out_release;
>  		}
>  
>  		inc_nlink(whiteout);
> @@ -1543,6 +1538,7 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
>  		iput(whiteout);
>  	}
>  	unlock_4_inodes(old_dir, new_dir, new_inode, whiteout);
> +out_release:
>  	ubifs_release_budget(c, &ino_req);
>  	ubifs_release_budget(c, &req);
>  	fscrypt_free_filename(&old_nm);
> 

Good find too. :-)
This function needs a cleanup, it is much longer than it should be.

Thanks,
//richard

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web