[PATCH] lib: fwts_log: free filenames on error condition

Colin King colin.king at canonical.com
Tue May 7 06:58:55 UTC 2013


From: Colin Ian King <colin.king at canonical.com>

Coverity CID#997343: Resource leak

We need to ensure filenames is free'd if it is already allocated
if fwts_log_filename() fails.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_log.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
index 85748cb..4667a76 100644
--- a/src/lib/src/fwts_log.c
+++ b/src/lib/src/fwts_log.c
@@ -579,8 +579,11 @@ char *fwts_log_get_filenames(const char *filename, const fwts_log_type type)
 	for (i=0; i<32; i++) {
 		fwts_log_type mask = 1 << i;
 		if (type & mask) {
-			if ((tmp = fwts_log_filename(filename, mask)) == NULL)
+			if ((tmp = fwts_log_filename(filename, mask)) == NULL) {
+				if (filenames)
+					free(filenames);
 				return NULL;
+			}
 
 			if (filenames) {
 				len += strlen(tmp) + 2;
-- 
1.8.1.2




More information about the fwts-devel mailing list