I'm not sure what is going on, but if I add prints to ModuleEnv.deinit, I can see that it is called twice in release builds, but only once in debug builds.
release free locations
/Users/bren077s/Projects/roc/zig-out/bin/roc check --verbose --no-cache /Users/bren077s/Projects/chip8/chip8_test_rom.roc
========== deinit ModuleEnv@16dde74b8 ==========
/Users/bren077s/Projects/roc/src/canonicalize/ModuleEnv.zig:137:36: 0x1048eb133 in deinit (roc)
std.debug.dumpCurrentStackTrace(null);
^
/Users/bren077s/Projects/roc/src/compile/compile_build.zig:738:25: 0x10496b6bf in parseHeaderDeps (roc)
defer env.deinit();
^
/Users/bren077s/Projects/roc/src/compile/compile_build.zig:470:51: 0x1049a66eb in build (roc)
var header_info = try self.parseHeaderDeps(root_abs);
^
/Users/bren077s/Projects/roc/src/cli/main.zig:2755:24: 0x10494758f in mainArgs (roc)
try build_env.build(filepath);
^
/Users/bren077s/Projects/roc/src/cli/main.zig:365:28: 0x104950b83 in main (roc)
const result = mainArgs(&allocs, args);
^
???:?:?: 0x1924a9d53 in ??? (???)
???:?:?: 0x0 in ??? (???)
========== deinit ModuleEnv@738c64320 ==========
/Users/bren077s/Projects/roc/src/canonicalize/ModuleEnv.zig:137:36: 0x1048eb133 in deinit (roc)
std.debug.dumpCurrentStackTrace(null);
^
/Users/bren077s/Projects/roc/src/compile/compile_package.zig:109:36: 0x1049a9553 in deinit (roc)
if (self.env) |*e| e.deinit();
^
/Users/bren077s/Projects/roc/src/cli/main.zig:2744:27: 0x104947feb in mainArgs (roc)
defer build_env.deinit();
^
/Users/bren077s/Projects/roc/src/cli/main.zig:365:28: 0x104950b83 in main (roc)
const result = mainArgs(&allocs, args);
^
???:?:?: 0x1924a9d53 in ??? (???)
???:?:?: 0x0 in ??? (???)
roc(36278,0x1ff214800) malloc: *** error for object 0x738810000: pointer being freed was not allocated
roc(36278,0x1ff214800) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort /Users/bren077s/Projects/roc/zig-out/bin/roc check --verbose --no-cache
debug frees
/Users/bren077s/Projects/roc/zig-out/bin/roc check --verbose --no-cache /Users/bren077s/Projects/chip8/chip8_test_rom.roc
========== deinit ModuleEnv@16f023410 ==========
/Users/bren077s/vendor/zig-0.14.1/lib/std/debug.zig:337:31: 0x10450fd37 in dumpCurrentStackTrace (roc)
writeCurrentStackTrace(stderr, debug_info, io.tty.detectConfig(io.getStdErr()), start_addr) catch |err| {
^
/Users/bren077s/Projects/roc/src/canonicalize/ModuleEnv.zig:137:36: 0x1045af11b in deinit (roc)
std.debug.dumpCurrentStackTrace(null);
^
/Users/bren077s/Projects/roc/src/compile/compile_build.zig:738:25: 0x1046787e7 in parseHeaderDeps (roc)
defer env.deinit();
^
/Users/bren077s/Projects/roc/src/compile/compile_build.zig:470:51: 0x1046ca5a7 in build (roc)
var header_info = try self.parseHeaderDeps(root_abs);
^
/Users/bren077s/Projects/roc/src/cli/main.zig:2755:24: 0x1045e3413 in checkFileWithBuildEnv (roc)
try build_env.build(filepath);
^
/Users/bren077s/Projects/roc/src/cli/main.zig:2819:45: 0x1045e205f in rocCheck (roc)
var check_result = checkFileWithBuildEnv(
^
/Users/bren077s/Projects/roc/src/cli/main.zig:415:40: 0x1046196af in mainArgs (roc)
.check => |check_args| rocCheck(allocs, check_args),
^
/Users/bren077s/Projects/roc/src/cli/main.zig:365:28: 0x10461bdc7 in main (roc)
const result = mainArgs(&allocs, args);
^
/Users/bren077s/vendor/zig-0.14.1/lib/std/start.zig:660:37: 0x10461c373 in main (roc)
const result = root.main() catch |err| {
^
???:?:?: 0x1924a9d53 in ??? (???)
???:?:?: 0x0 in ??? (???)
No errors found in 241.6 ms for /Users/bren077s/Projects/chip8/chip8_test_rom.roc%
Also, of note, the error specifically comes from freeing part of the type checking state I think. The DescStore in the TypeStore. So it could also be related to something type checking specfic and not moduleenv technically.