ubifs: Fix memory leak in lprobs self-check
authorRichard Weinberger <richard@nod.at>
Tue, 12 Jun 2018 18:49:45 +0000 (20:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 9 Sep 2018 17:56:00 +0000 (19:56 +0200)
commit eef19816ada3abd56d9f20c88794cc2fea83ebb2 upstream.

Allocate the buffer after we return early.
Otherwise memory is being leaked.

Cc: <stable@vger.kernel.org>
Fixes: 1e51764a3c2a ("UBIFS: add new flash file system")
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ubifs/lprops.c

index 6c3a1abd0e22c9e033da093e4f21b4d3ad9898b2..780a436d8c45b73c91c3de209a4f607a33f324b2 100644 (file)
@@ -1091,10 +1091,6 @@ static int scan_check_cb(struct ubifs_info *c,
                }
        }
 
-       buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
        /*
         * After an unclean unmount, empty and freeable LEBs
         * may contain garbage - do not scan them.
@@ -1113,6 +1109,10 @@ static int scan_check_cb(struct ubifs_info *c,
                return LPT_SCAN_CONTINUE;
        }
 
+       buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
        sleb = ubifs_scan(c, lnum, 0, buf, 0);
        if (IS_ERR(sleb)) {
                ret = PTR_ERR(sleb);