So I'm trying to exploit tgc for C++ automatic GC dream:
class object {
public: object();
public: virtual ~object() {}
};
void* __cdecl operator new(unsigned int size) throw(std::bad_alloc) {
tgc_run(&gc);
return tgc_alloc(&gc, size);
}
void* __cdecl operator new[](unsigned int size) throw(std::bad_alloc) {
tgc_run(&gc);
return tgc_calloc(&gc, 1, size);
}
void __cdecl operator delete(void *mem) throw() {
tgc_run(&gc);
return tgc_free(&gc, ptr);
}
object::object() {
auto dtor = (void(*)(void*))**(void***)this;
tgc_set_dtor(&gc, this, dtor);
}
The dtor is virtualized. However, when the program is sweeping and deleting the object, the dtor was not able to be called, and instead a segfault occurred. Can someone figure out what's happening?
So I'm trying to exploit tgc for C++ automatic GC dream:
The
dtoris virtualized. However, when the program is sweeping and deleting theobject, thedtorwas not able to be called, and instead asegfaultoccurred. Can someone figure out what's happening?