[erlang-questions] How to track down intermittent segfaults in a threaded NIF

Scott Ribe scott_ribe@REDACTED
Tue May 29 17:31:48 CEST 2018


> On May 29, 2018, at 9:16 AM, Igor Clark <igor.clark@REDACTED> wrote:
> 
> So, do I have this right: the point of the Guard Malloc is to make the crash happen at the time of allocation, rather than delayed until something trying to access it triggers the segfault; so if I get a crash while running like this, I should be able to just check in the Console debug log, and the stack trace should show where the bug actually is?

At the time of the illegal access, not the allocation. Yes, that's the point, you get a stack trace showing you illegal access.

However, the BEAM allocator will reduce its effectiveness. When you malloc in your C code, you get a block set up such that accessing just past it (or potentially before it) will cause an immediate crash. When you free it, it's then set up such that accessing will cause an immediate crash. But if you use Erlang's allocation routines, Erlang may malloc a bigger block with those protections, then hand out multiple suballocations, and access beyond the end of one of those can simply corrupt the next one without crashing at that point.

You should also be using MallocScribble & MallocPreScribble.






More information about the erlang-questions mailing list