[Skiboot] [PATCH 7/8] libflash: fix resource leaks on errors in ffs_open_image

Stewart Smith stewart at linux.vnet.ibm.com
Tue Nov 17 15:39:06 AEDT 2015


Signed-off-by: Stewart Smith <stewart at linux.vnet.ibm.com>
---
 libflash/libffs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libflash/libffs.c b/libflash/libffs.c
index 3010a61f3cef..5563e52bc3ed 100644
--- a/libflash/libffs.c
+++ b/libflash/libffs.c
@@ -234,12 +234,16 @@ int ffs_open_image(int fd, uint32_t size, uint32_t toc_offset,
 
 	/* Read the cached map */
 	rc = lseek(fd, toc_offset, SEEK_SET);
-	if (rc < 0)
+	if (rc < 0) {
+		free(f->cache);
+		free(f);
 		return FLASH_ERR_PARM_ERROR;
+	}
 
 	rc = read(fd, f->cache, f->cached_size);
 	if (rc != f->cached_size) {
 		FL_ERR("FFS: Error %d reading flash partition map\n", rc);
+		free(f->cache);
 		free(f);
 		return FLASH_ERR_BAD_READ;
 	}
-- 
2.1.4



More information about the Skiboot mailing list