Merge "ImgIoUtilReadFile: fix file leak upon error"

This commit is contained in:
Pascal Massimino 2017-11-30 00:24:51 +00:00 committed by Gerrit Code Review
commit 0d5d029c18

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