Long running C++ NIF segfaults

This is where the program crashes, I call the image function ~100 times (not always the same number of times) then it crashes: