Curious arena allocator behavior - (UPDATE: not an issue)


So I’m working on a game in Raylib and I wanted to use an ArenaAllocator that wraps a child heap page allocator for temp garbage that should be cleaned up per each frame iteration.

The arena has a reset() method for doing just this allowing you to reuse the arena over and over.

So at application start I wired this up and use it in a few key locations for temp data and then call reset at the end of my game event loop.

This pattern is great for any allocations that don’t need to live longer than a single game frame.

However this particular setup causes a segmentation fault so I ended up using a General Purpose allocator as the child. Now everything works.

Does anyone know why a page heap allocator won’t work for a child? Is this a bug in the stdlib?

Any guidance is appreciated!

We would have the specific code in question. It sounds like a use-after-free.

1 Like

@LucasSantos91 is right - page_allocator works great with arenas so there’s something else going on here.

1 Like

Ok, I’ll have to reduce it to a small code example and see if I can demonstrate what I’m doing.

I thought it was a use after free as well but I feel like I’ve eliminated that possibility.

But getting extra eyes on it can’t hurt.

If you don’t call free, it is normal that everything works.
If you are freeing everything something is terribly wrong.

Depending on the mode either all allocations are freed or all but the first allocation are freed.
When the memory is freed and the code tries to access it, you get a segmentation fault.

Is there a stack trace for the segmentation fault? It must point directly to the code that access the freed memory.

1 Like

Ok, this must have been user error on my part.

Through my refactor to use a GPA allocator I must have fixed something because when I switched back to a page allocator everything is still working as intended.

Everything is ok…but thanks all for double checking my sanity on this.

1 Like