cURL / Mailing Lists / curl-library / Single Mail


Re: Memory leak in getinmemory.c example?

From: Daniel Stenberg <>
Date: Sun, 6 Dec 2015 16:16:55 +0100 (CET)

On Sun, 6 Dec 2015, wrote:

> Correct me if I am wrong, but according to
> 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.

List admin:
Received on 2015-12-06