From ecb40c64b5a37d353b75a690010ff8bc72252e4a Mon Sep 17 00:00:00 2001 From: Srivardhan Hebbar Date: Mon, 23 Nov 2015 20:44:27 +0900 Subject: [PATCH] evas_fb: Handling memory leak on realloc failure. Summary: I thought its better to fail and return null if realloc fails than to continue. So returning by closing all openend file. Signed-off-by: Srivardhan Hebbar Reviewers: cedric, illogict Differential Revision: https://phab.enlightenment.org/D3232 --- src/modules/evas/engines/fb/evas_fb_main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/modules/evas/engines/fb/evas_fb_main.c b/src/modules/evas/engines/fb/evas_fb_main.c index de6f65a..3b8b23b 100644 --- a/src/modules/evas/engines/fb/evas_fb_main.c +++ b/src/modules/evas/engines/fb/evas_fb_main.c @@ -341,7 +341,7 @@ fb_list_modes(unsigned int *num_return) { FILE *f; char line[256], label[256], value[256]; - FB_Mode *modes = NULL; + FB_Mode *modes = NULL, *temp; int num; num = 0; @@ -365,7 +365,15 @@ fb_list_modes(unsigned int *num_return) int timings = 0; num++; + temp = modes; modes = realloc(modes, num * sizeof(FB_Mode)); + if (!modes) + { + free(temp); + fclose(f); + *num_return = 0; + return NULL; + } memset(modes + (num - 1), 0, sizeof(FB_Mode)); modes[num - 1].width = atoi(f1); modes[num - 1].height = atoi(f2); -- 2.7.4