Can Zig's test runner detect resource leaks?

If you use std.testing.allocator, the test runner will detect memory leaks and print stack traces. But memory is not the only resource. You can leak in other ways:

  • Call openFile, but never call File.close
  • Call process.Child.spawn, but never call kill or wait
  • Call Thread.spawn, but never call join or detach
  • Call myUserCodeStart, but never call myUserCodeEnd

Does Zig have any way to sanitize for these kinds of leaks?

I think this might make it so that we can do similar detection, for some of those other resources:

But the last one seems like it would require some sort of custom validation tooling, or adding support for validation, unless you also invent some sort of interface convention for your myUserCodeStart functions.

1 Like

It is not currently implemented, but the core team is planning to handle these use cases.

2 Likes
3 Likes

Thanks for the links!

I actually just mentioned this on IRC but I would think that the IO abstraction will make this pretty easy to implement.

1 Like