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 <sri.hebbar@samsung.com>

Reviewers: cedric, illogict

Differential Revision: https://phab.enlightenment.org/D3232
This commit is contained in:
Srivardhan Hebbar 2015-11-23 20:44:27 +09:00 committed by Jean-Philippe Andre
parent 51a65c970f
commit ecb40c64b5
1 changed files with 9 additions and 1 deletions

View 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);