<p>In this pattern:</p>
<pre><code>ptr = realloc( ptr , new_size );
</code></pre>
<p><code>realloc</code> may fail when HEAP memory is exhausted, then return 0, and overwrite <code>ptr</code> with a NULL pointer...<br>
But <code>realloc</code> did not <code>free(ptr)</code>, it rather leaves it untouched!</p>
<p>OK, we rarely exhaust HEAP nowadays, and consequences might be catastrophic anyway.<br>
But it is a code smell. It should be written like this:</p>
<p>aux = realloc( ptr , new_size );<br>
if( aux == NULL ) /* handle_the_error */ {};<br>
else ptr = aux;</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/335">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AhLyW030A1AVEp2j8GEez4bs5qx0Lmdiks5u-9WOgaJpZM4ZmCfu">mute the thread</a>.<img src="https://github.com/notifications/beacon/AhLyW3uNzK3o2LIG41iLChHjM123qHLaks5u-9WOgaJpZM4ZmCfu.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"code smell (IntelliSense C6308): realloc could cause a memory leak (#335)"}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/335"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/335",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/335",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>