Patch: fix intermittent crash in KHTML Thai Word Break

Koos Vriezen koos.vriezen at xs4all.nl
Tue Mar 1 19:05:06 GMT 2005


On Tue, Mar 01, 2005 at 06:50:42PM +0000, Germain Garand wrote:
> Le mardi 01 Mars 2005 17:33, Koos Vriezen a écrit :
> > I always though that 'delete x' calls the operator delete of X that will
> > call the destructor of X, 
> 
> I think destructors are called before operator delete, otherwise placement new 
> would be even more hackish :)

Ah yes of course, otherwise destructor would work on a deleted object
... test code ...

#include <iostream>

struct X {
    X () { std::cout << "ctor\n"; }
    ~X () { std::cout << "dtor\n"; }
    void operator delete (void * s) { std::cout << "delete\n"; free (s); }
    void* operator new (size_t s) { std::cout << "new\n"; return malloc (s); }
};

int main () {
    X * x = new X;
    delete x;
    return 0;
}

$ g++  tor.cpp
$ ./a.out
new
ctor
dtor
delete

Oh well, who needs test code if one can reason :-)

Koos




More information about the kfm-devel mailing list