You ignore osize.
As does the Lua default alloc function:
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t
nsize) {
(void)ud;
(void)osize;
if (nsize == 0) {
free(ptr);
return NULL;
}
else
return realloc(ptr, nsize);
}
Osize can imo be used to free allocated memory so the custom
allocator doesn't need to remember the allocated size if it is
lazy. Inside my simple test allocator I don't care about freeing. I
just allocate and leak.
There must be another reason why it doesn't work.
Regards
Joerg