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.

Reply via email to