News for hackers. Stuff that matters.
Re:Ode to the use-after-free: one vulnerable function, a tho... by to3m on Monday May 08, 2017 @05:30PM (#14295792)
There is no generic pointer-to-pointer in C. You get an incompatible-pointer-types warning in gcc when trying to use void * * : https://godbolt.org/g/vxWFvl

There is probably scope for use of C11 _Generic, but I don't think you could support user-defined types in that way.

The usual macro problems apply when trying to do it as a macro:

    #define FREE(X) (free(X),(X)=NULL,(void)0)
In C++ you can do something like this, which works well enough: (I don't use this specifically myself, but I have something similar for COM objects)

    template<class T>
    static void Free(T *&p) {
        free(p);
        p=nullptr;
    }
This isn't completely useless, but it's not worth sweating blood over. Personally I think I've had more mileage from good-quality debug functionality in the memory allocator: fill newly-allocated and newly-freed regions with junk; check junk and metadata periodically; unmap regions promptly; and so on.

There are no comments on this comment yet.