curl-library
Re: Memory leak in getinmemory.c example?
Date: Sun, 6 Dec 2015 16:16:55 +0100 (CET)
On Sun, 6 Dec 2015, henrik_at_gassmann.onl wrote:
> Correct me if I am wrong, but according to
> http://en.cppreference.com/w/c/memory/realloc you still have to free the old
> pointer if realloc fails (i.e. returns NULL), which is obviously impossible
> if you directly overwrite it.
That is entirely correct. But this is an example that is meant to be simple
and easy to read. It does not have enough error checks. As the example page on
the web site says:
These files are intended as examples only. In the interest of simplicity and
clarity, they might not include proper error handling and might produce
compiler warnings on some platforms. Real-world applications should pay more
attention to these issues.
The example also exits very shortly after so it a leak in the case of an out
of memory situation would not be a big problem.
-- / daniel.haxx.se ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2015-12-06