News for hackers. Stuff that matters.
Re:The lost malloc() by dgrunwald on Wednesday November 04, 2026 @11:50AM (#50368285)
But it's possible for `delete tmp;` to call a user-defined `operator delete()` in the derived class! https://godbolt.org/z/hvePa6jMP

The way this works under the hood is that every polymorphic class has two destructors (so two destructor entries in the vtable): the "complete object destructor" is the ~A() you know from C++, and then there's also the "deleting destructor" which combines ~A() + delete.

So the deleting destructor can call free() while knowing the derived object size, even for a delete-via-base-class-pointer.

There are no comments on this comment yet.