I have added my custom memory functions to scriptarray, seems to work fine. But when I try to create a too large buffer, I get a SIGSEV too.
I realized that if we run out of sandbox's memory, AngelScript wouldn't have space to allocate for errors handling. So I've added a condition in memFree : if memLimit is reached, memFree will return 0 only once, and will not check the limit after (because the program using the sandbox is assumed to have stopped).
I recompiled and retried my test : When the big buffer is created, the context exception is set to "Out of memory", the script stops. Then the console prints "An exception 'Out of memory' occurred. Please correct the code and try again." But when the engine is released, I get SIGSEV anyway :
I've successfully implemented the custom alloc and free functions, but now I have a new problem :
When I reach the memory limit (actually just before), how do I inform the program to stop the sandbox without crash? Because I'm currently returning 0 (out of memory) in memAlloc, but then my program gets a SIGSEV and closes immediately.
Thanks for your quick answer. Actually, I forgot to call cleanup functions, now everything is ok about memory leaks.
I think that adding extra-data to memory blocks will be better for portability. I had also imagined to first allocate a big memory block the size of the memory limit (not so much), and then using it to store script's data, taking care not run out of it... but I don't know how to manage this.
In my project, every user will be able to send scripts to a server, that will run them (each in separated sandboxes), so I have to secure the script manager a lot to avoid spamming. Also, are the scriptarray or scriptstdstring addons using the same alloc functions? Or do I have to modify them?
I will examine your code, it will be very useful for the moment