[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] code smell (IntelliSense C6308): realloc could cause a memory leak (#335)

Nicolas Cellier notifications at github.com
Tue Jan 1 21:39:26 UTC 2019


In this pattern:

    ptr = realloc( ptr , new_size );

`realloc` may fail when HEAP memory is exhausted, then return 0, and overwrite `ptr` with a NULL pointer...
But `realloc` did not `free(ptr)`, it rather leaves it untouched!

OK, we rarely exhaust HEAP nowadays, and consequences might be catastrophic anyway.
But it is a code smell. It should be written like this:

   aux = realloc( ptr , new_size );
   if( aux == NULL ) /* handle_the_error */ {};
   else ptr = aux;


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/335
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20190101/366734ed/attachment-0001.html>


More information about the Vm-dev mailing list