Fix resource leaks in bin2o.c

Fix resource leaks in bin2o.c
This commit is contained in:
ryancaicse
2022-02-07 15:16:25 +08:00
committed by GitHub
parent 64d91e402a
commit a78df04996

View File

@@ -362,17 +362,20 @@ int main(int argc, char *argv[])
buffer = malloc(size);
if (buffer == NULL) {
printf("Failed to allocate memory.\n");
fclose(dest);
return 1;
}
if (fread(buffer, 1, size, source) != size) {
printf("Failed to read file.\n");
fclose(dest);
return 1;
}
fclose(source);
if (!(dest = fopen(f_dest, "wb+"))) {
printf("Failed to open/create %s.\n", f_dest);
fclose(dest);
return 1;
}