arrbee/libgit2 — pull request #1 by arrbee (2011-12-15 00:45:00+00:00)
Title: Proof of concept test memory alloc hooks

This enables a new compile-time flag TEST_ALLOC which invokes an allocation hook prior to every malloc, realloc, free, etc. that can intercept and modify the behavior of the allocation. By returning a value less than GIT_SUCCESS, the operation will be caused to fail. For realloc, returning a value greater than 0, will cause a success but force the pointer to be moved.

As an added bit of paranoia, just enabling this will cause both realloc and free to write a zero byte to the old block before releasing it in an attempt to catch errors involving the use of an old buffer, and malloc will intentionally fill the block with garbage bytes.