[flac-dev] [PATCH] for potential memory leaks

Erik de Castro Lopo mle+la at mega-nerd.com
Sat Aug 22 00:01:06 PDT 2015

lvqcl wrote:

> libFLAC has several places like this:
>      if(0 == (ptr = realloc(ptr, size)))
>          return false;
> which results in memory leaks if realloc fails (the old value of ptr is lost).
> The patch should fix this.

I found a problem with this patch.

Specifcally, where ever the patch tries to free() the old pointer
where safe_realloc_mul_2op_() fails, can result in a double free().

This is because, when safe_realloc_mul_2op_() has either of its size
arguments equal to zero, will call realloc(ptr, 0) which according to
the realloc manpage  is an implicit free() anyway.

Working on a fix for this and re-visiting some of this realloc()

Erik de Castro Lopo

More information about the flac-dev mailing list