summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Donnellan <andrew.donnellan@au1.ibm.com>2016-05-04 11:22:57 +1000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2016-05-06 13:57:30 +1000
commit87fa4885310b6c6b79e31d79d192ba9ea90cf236 (patch)
tree306127e71829d8e2119d5a9f31c941bf0ce9f185
parent81f28af2bd94cc552aef1a7b959e4c6b84457ce7 (diff)
downloadpetitboot-87fa4885310b6c6b79e31d79d192ba9ea90cf236.zip
petitboot-87fa4885310b6c6b79e31d79d192ba9ea90cf236.tar.gz
lib/flash: fix resource leak in flash_setup_buffer() error paths
Some error paths in flash_setup_buffer() fail to free the flash_info struct or close the open ffs before they return. Change them to goto the cleanup code at the end. Separate the cleanup code into separate labels depending on whether we need to call ffs_close(), arch_flash_close() and talloc_free(). Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
-rw-r--r--lib/flash/flash.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/flash/flash.c b/lib/flash/flash.c
index b6188a0..1384118 100644
--- a/lib/flash/flash.c
+++ b/lib/flash/flash.c
@@ -82,26 +82,26 @@ static struct flash_info *flash_setup_buffer(void *ctx, const char *partition)
rc = arch_flash_init(&info->bl, NULL, true);
if (rc) {
pb_log("Failed to init mtd device\n");
- return NULL;
+ goto out;
}
rc = blocklevel_get_info(info->bl, &info->path, &info->size,
&info->erase_granule);
if (rc) {
pb_log("Failed to retrieve blocklevel info\n");
- return NULL;
+ goto out_flash;
}
rc = ffs_init(0, info->size, info->bl, &info->ffs, 1);
if (rc) {
pb_log("%s: Failed to init ffs\n", __func__);
- goto out;
+ goto out_flash;
}
rc = partition_info(info, partition);
if (rc) {
pb_log("Failed to retrieve partition info\n");
- goto out;
+ goto out_ffs;
}
/* Check if there is a second flash side. If there is not, or
@@ -139,8 +139,11 @@ static struct flash_info *flash_setup_buffer(void *ctx, const char *partition)
}
return info;
-out:
+out_ffs:
+ ffs_close(info->ffs);
+out_flash:
arch_flash_close(info->bl, NULL);
+out:
talloc_free(info);
return NULL;
}
OpenPOWER on IntegriCloud