diff mbox

ceph: fix potential memory leak

Message ID 1519885491-163018-1-git-send-email-cgxu519@icloud.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chengguang Xu March 1, 2018, 6:24 a.m. UTC
There is lack of cache destroy operation for ceph_file_cachep
when failing from fscache register.

Signed-off-by: Chengguang Xu <cgxu519@icloud.com>
---
 fs/ceph/super.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Ilya Dryomov March 1, 2018, 2:41 p.m. UTC | #1
On Thu, Mar 1, 2018 at 7:24 AM, Chengguang Xu <cgxu519@icloud.com> wrote:
> There is lack of cache destroy operation for ceph_file_cachep
> when failing from fscache register.
>
> Signed-off-by: Chengguang Xu <cgxu519@icloud.com>
> ---
>  fs/ceph/super.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ceph/super.c b/fs/ceph/super.c
> index a62d2a9..564bddc 100644
> --- a/fs/ceph/super.c
> +++ b/fs/ceph/super.c
> @@ -711,14 +711,17 @@ static int __init init_caches(void)
>                 goto bad_dentry;
>
>         ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
> -
>         if (!ceph_file_cachep)
>                 goto bad_file;
>
> -       if ((error = ceph_fscache_register()))
> -               goto bad_file;
> +       error = ceph_fscache_register();
> +       if (error)
> +               goto bad_fscache;
>
>         return 0;
> +
> +bad_fscache:
> +       kmem_cache_destroy(ceph_file_cachep);
>  bad_file:
>         kmem_cache_destroy(ceph_dentry_cachep);
>  bad_dentry:

Applied.

Thanks,

                Ilya
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index a62d2a9..564bddc 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -711,14 +711,17 @@  static int __init init_caches(void)
 		goto bad_dentry;
 
 	ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
-
 	if (!ceph_file_cachep)
 		goto bad_file;
 
-	if ((error = ceph_fscache_register()))
-		goto bad_file;
+	error = ceph_fscache_register();
+	if (error)
+		goto bad_fscache;
 
 	return 0;
+
+bad_fscache:
+	kmem_cache_destroy(ceph_file_cachep);
 bad_file:
 	kmem_cache_destroy(ceph_dentry_cachep);
 bad_dentry: