ImgIoUtilReadFile: fix file leak upon error

the file was not closed in case of malloc error.

Change-Id: I5f8b22d7d0da6d2c8c2dd245cdd57994e3ddea3a
This commit is contained in:
Pascal Massimino 2017-11-29 21:30:22 +01:00
parent b299c47eac
commit ae568ce7c4

View File

@ -88,7 +88,12 @@ int ImgIoUtilReadFile(const char* const file_name,
file_size = ftell(in);
fseek(in, 0, SEEK_SET);
file_data = malloc(file_size);
if (file_data == NULL) return 0;
if (file_data == NULL) {
fclose(in);
fprintf(stderr, "memory allocation failure when reading file %s\n",
file_name);
return 0;
}
ok = (fread(file_data, file_size, 1, in) == 1);
fclose(in);