It's worth noting that<p><pre><code> realloc(ptr, 0)
</code></pre>
behavior is undefined. The vast majority of modern C libraries will implement it as<p><pre><code> return free(ptr), NULL;
</code></pre>
and it will be documented on man pages as such, but there <i>are</i> systems where this will be equivalent to<p><pre><code> return free(ptr), malloc(0);
</code></pre>
Furthermore, in theory, this is also permitted:<p><pre><code> return NULL;
</code></pre>
so as tempting as realloc() might be as a single override for implementing custom allocators, there are some worms.