Stream: compiler development

Topic: zig-compiler: double free in Release builds


view this post on Zulip Brendan Hansknecht (Oct 16 2025 at 03:49):

This might be hard to debug. I have a sample roc file here: https://github.com/bhansconnect/chip8_op_test/blob/main/chip8_test_rom.roc

with a debug build of the compiler roc check works just fine. I have been running with --verbose --no-cache as well.

With a release build of the compiler, it segfaults due to a double free.

If i use a debug allocator in the release build to hopefully get a stack trace, but it just hangs.


I tried to debug this a little bit the other day.
This is where it hangs:
Captura de pantalla 2025-10-15 a la(s) 8.33.08 p.m..png

Which is the same location the double free happens:

lldb backtrace

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

debug frees

Anyone have thoughts?

view this post on Zulip Luke Boswell (Oct 16 2025 at 03:53):

I'm really not sure

view this post on Zulip Brendan Hansknecht (Oct 16 2025 at 03:55):

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.

view this post on Zulip Luke Boswell (Oct 16 2025 at 03:56):

It's the debug vs release thing that has me a little stumped

view this post on Zulip Brendan Hansknecht (Oct 16 2025 at 03:56):

So I see two confusions:

  1. Why doesn't debug free things here? What is the delta?
  2. It isn't the entire moduleenv being double freed. just the DescStore. What is special about it?

Last updated: Oct 18 2025 at 12:13 UTC