Merge pull request #2067 from bimbashrestha/res-leak

[bug] adding fclose before return
This commit is contained in:
Bimba Shrestha 2020-04-03 15:51:59 -05:00 committed by GitHub
commit 009a92f749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,11 +100,14 @@ static char* readFile(const char* filename, size_t* size) {
buf = malloc(*size);
if (buf == NULL) {
fprintf(stderr, "malloc failed\n");
fclose(f);
return NULL;
}
bytes_read = fread(buf, 1, *size, f);
if (bytes_read != *size) {
fprintf(stderr, "failed to read whole file\n");
fclose(f);
free(buf);
return NULL;
}