[PATCH] fix memory leak in UBI scanning unit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In drivers/mtd/ubi/scan.c::paranoid_check_si() there's a memory leak.
If the call 
	err = ubi_io_is_bad(ubi, pnum);
returns <0, then we'll return with out freeing (and thus leak) buf.
This patch eliminates the memory leak by freeing buf before returning.

Problem spotted by the Coverity checker.


Signed-off-by: Jesper Juhl <[email protected]>
-- 

 drivers/mtd/ubi/scan.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 473f320..8ff9730 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -1310,9 +1310,10 @@ static int paranoid_check_si(const struct ubi_device *ubi,
 	memset(buf, 1, ubi->peb_count);
 	for (pnum = 0; pnum < ubi->peb_count; pnum++) {
 		err = ubi_io_is_bad(ubi, pnum);
-		if (err < 0)
+		if (err < 0) {
+			kfree(buf);
 			return err;
-		else if (err)
+		} else if (err)
 			buf[pnum] = 0;
 	}
 






-- 
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux