evas_fb: Handling memory leak on realloc failure.
authorSrivardhan Hebbar <sri.hebbar@samsung.com>
Mon, 23 Nov 2015 11:44:27 +0000 (20:44 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 23 Nov 2015 11:44:28 +0000 (20:44 +0900)
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 <sri.hebbar@samsung.com>
Reviewers: cedric, illogict

Differential Revision: https://phab.enlightenment.org/D3232

src/modules/evas/engines/fb/evas_fb_main.c

index de6f65a..3b8b23b 100644 (file)
@@ -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);