Unless I&#x27;m reading your example incorrectly, it&#x27;s pretty easy to catch those if, in foo_destroy, you ensure that you don&#x27;t try to free a null pointer.<p>&gt;  It&#x27;s just a minimal example.<p>I know -- but it tends to be confusing if you free() something in another scope than the one where you&#x27;re malloc()-ing it. That&#x27;s why your example, even if minimal, seemed confusing.<p>The obvious exception is if you have some reference counting mechanism&#x2F;GC mechanism in place -- but then the wise thing to do is to <i>not</i> manually touch pointers all over the code.