]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fs: ubifs: Ensure buf is freed before return
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Fri, 3 Oct 2025 10:42:50 +0000 (11:42 +0100)
committerHeiko Schocher <hs@nabladev.com>
Wed, 8 Oct 2025 09:35:47 +0000 (11:35 +0200)
Returning directly after buf has been allocated will result in a memory
leak. Instead set the error code and goto the common unwind code to
ensure that buf will be freed before returning.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
fs/ubifs/lprops.c

index a9e22abe6b401ecc4afb15c632dadbe23199c39f..74beb853b6e1da5076cbc8aad77ae26a76fa3580 100644 (file)
@@ -1096,14 +1096,16 @@ static int scan_check_cb(struct ubifs_info *c,
                lst->empty_lebs += 1;
                lst->total_free += c->leb_size;
                lst->total_dark += ubifs_calc_dark(c, c->leb_size);
-               return LPT_SCAN_CONTINUE;
+               ret = LPT_SCAN_CONTINUE;
+               goto out;
        }
        if (lp->free + lp->dirty == c->leb_size &&
            !(lp->flags & LPROPS_INDEX)) {
                lst->total_free  += lp->free;
                lst->total_dirty += lp->dirty;
                lst->total_dark  +=  ubifs_calc_dark(c, c->leb_size);
-               return LPT_SCAN_CONTINUE;
+               ret = LPT_SCAN_CONTINUE;
+               goto out;
        }
 
        sleb = ubifs_scan(c, lnum, 0, buf, 0);