From 45133922aaa47035da317a5dd618d60973002661 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Thu, 13 Aug 2015 15:25:59 +0100 Subject: [PATCH] mraa.c: Fix ressource leaks during error handling Signed-off-by: Brendan Le Foll --- src/mraa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mraa.c b/src/mraa.c index d49be29..9f0c57a 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -354,6 +354,9 @@ mraa_file_contains(const char* filename, const char* content) size_t len = 1024; char* line = malloc(len); FILE* fh = fopen(file, "r"); + if (fh == NULL) { + return 0; + } while ((getline(&line, &len, fh) != -1) && (found == 0)) { if (strstr(line, content)) { found = 1; @@ -380,6 +383,9 @@ mraa_file_contains_both(const char* filename, const char* content, const char* c size_t len = 1024; char* line = malloc(len); FILE* fh = fopen(file, "r"); + if (fh == NULL) { + return 0; + } while ((getline(&line, &len, fh) != -1) && (found == 0)) { if (strstr(line, content) && strstr(line, content2)) { found = 1;