Fix resource leaks (#439)

* Free memory

* Close file handle
This commit is contained in:
Johan Mattsson
2023-12-18 03:19:33 +02:00
committed by GitHub
parent 4dcbcf9ad5
commit 121575febe
+4 -1
View File
@@ -198,8 +198,10 @@ M3Result repl_load_hex (u32 fsize)
hex_idx = 0;
}
}
if (!fgets(hex, 3, stdin)) // Consume a newline
if (!fgets(hex, 3, stdin)) { // Consume a newline
free(wasm);
return "cannot read EOL";
}
}
IM3Module module;
@@ -445,6 +447,7 @@ M3Result repl_dump ()
return "cannot open file";
}
if (fwrite (mem, 1, len, f) != len) {
fclose (f);
return "cannot write file";
}
fclose (f);