lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If free must return an error because of pointer corruption, the only best solution is to let the lua engine generate a panic and abort the whole process as it is corrupted for all threads; in that case calling luaD_throw in your free tests is the only thing you can do, it will panic and the lua process will be terminated... Then you dont need to return anything else than NULL in a free operation.
The code in lmem.c then never needs to check the L->status...

Except if the memory pool used by your allocator is isolated from the other pool used by other standard allocators in Lua (for example your alloc/free algorithm allocates and check pointers only valid in this pool, inwhich case instead of panicing, you can just invalidate the whole pool and recreate a new one (and all other threads still having pointers in the old pool may just continue to use them as as, but won't get any new pointer from this old pool but from a new clean pool and their attempt to free objects will just be ignored. The old pool will persist as long as there are pointers into it, then Lua will free the old pool itself in one operation during garbage collection.

But if you've detected pointer corruption inside your pool, all threads using objects allocated in that pool are using corrupted objects: do you really want these threads to continue running and using the corrupted objects without being stopped? I see no clear way to recover rather than killing all these threads abruptly.



Le sam. 16 mai 2020 à 15:44, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> a écrit :
> The new allocator in specific circumstances decides to deny its operations, allocations and free
> (also free because it checks for possible corruptions of the memory pointers).

lua_Alloc should behave externally like realloc. In particular, the
allocator should return NULL when it cannot fulfill an allocation
request.

On the other hand, the manual says: "When nsize is zero, the allocator
must behave like free and return NULL.". So you cannot signal errors
in free by returning NULL. I think you cannot signal erros in free at
all. The allocator cannot set L->status because it does not receive L.
Moreover, the code in lmem.c never checks L->status.
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org