On Thu, Jun 25, 2009 at 4:14 PM, Peter Ammon<[email protected]> wrote:
> 2) Require that malloc be robust against multiple free()s on the same
> pointer
>
> The second solution is a lot easier to implement.

Can you elaborate on this? Thinking about how to accomplish this, it
seems like an extremely difficult problem. The only thing I've been
able to come up with that would work would be to make all pointers be
implemented as an address plus a counter. Then when you call free, it
checks your pointer's counter against the latest one allocated there,
and if your counter is stale, it does nothing. This would be a massive
change to the language that would break binary compatibility with
everything and bloat pointer sizes hugely, since it would really
require at least 64 bits for the counter to be properly robust.

Is there some easy solution to this that I'm overlooking? Silently
returning if you pass a freed block is not sufficient, because that
block could have been reused by the time the second free() happens,
causing a chunk of memory owned by someone else to be spontaneously
destroyed.

Mike
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to