On Sunday, 8 February 2015 at 12:43:38 UTC, FG wrote:
On 2015-02-08 at 03:19, Andrei Alexandrescu wrote:
Indeed we have no safe way to wrap free.

How about this to prevent double free:

Wrapped malloc keeps a static thread-local lookup structure for successful allocations (if having to release memory from the same thread is an acceptable requirement).

Wrapped free looks up the pointer in that lookup structure and, if found, frees memory, removes the lookup entry and sets the argument of the call to zero (if it was a pointer) or sets its length and ptr to zero (if it was a dynamic array).

It's not completely safe, but for that GC would have to be used instead.

A typical C debug library trick for when the money for a proper tool isn't available.


--
Paulo

Reply via email to