Skip to content

Commit

Permalink
UBI: fix leak in ubi_scan_erase_peb
Browse files Browse the repository at this point in the history
Coverity (1769) found the following problem: if the erase counter
overflow check triggers, ec_hdr is leaked.

Moving the allocation after the overflow check should take care of it.

Signed-off-by: Florin Malita <fmalita@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
  • Loading branch information
Florin Malita authored and Artem Bityutskiy committed Oct 14, 2007
1 parent bbf2501 commit dcec4c3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/mtd/ubi/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,6 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi,
int err;
struct ubi_ec_hdr *ec_hdr;

ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
if (!ec_hdr)
return -ENOMEM;

if ((long long)ec >= UBI_MAX_ERASECOUNTER) {
/*
* Erase counter overflow. Upgrade UBI and use 64-bit
Expand All @@ -686,6 +682,10 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi,
return -EINVAL;
}

ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
if (!ec_hdr)
return -ENOMEM;

ec_hdr->ec = cpu_to_be64(ec);

err = ubi_io_sync_erase(ubi, pnum, 0);
Expand Down

0 comments on commit dcec4c3

Please sign in to comment.