lua-users home
lua-l archive

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


I just got into an problem with tolua 3.2.2, which broke my code completely.
I discovered that tolua allocates memory for userdata types in c++
environments via the new function. But the memory is freed with the function
free (in toluaI_tm_undoclone) and not the function delete. There is even a
comment on that line that looks like the author knew what he did
("free(clone); /* no destructor: use raw free */").

The problem is:

1. this is a violation of any c++ standard I am aware of. There is no
guarantee that the different memory functions work on the same heap. Ok this
may sound a bit theoretical but

2. I overloaded globally new and delete to use my own memory management. So
now the memory is allocated via my own operator new (which gets its memory
not via the c++ crt but directly from the OS) and freed via the crt function
free, which throws lots of assertments about freeing memory about which the
crt knows nothing.

I could easily fix this with an #ifdef __cpluscplus in the undoclone
function but I want to know if there will be problems with that.