memory leak or something wrong

Brandon Black blblack at
Mon Jun 18 08:56:43 CEST 2012

On Mon, Jun 18, 2012 at 12:43 AM, yao liufeng <ylfroy at> wrote:
> can someone help to clarify whether it's a
> memory leak or something wrong with the code? Thanks!

Googling around, it seems like in the past year or two there's been
some flareup between C99/C1X, POSIX, and glibc about interpretations
of what the right/acceptable/conforming behavior of realloc(p,0) is:

In practice, on Fedora 16 (glibc 2.14), I've observed a very small
leak on code like yours (you can even leave libev out of this, it's
all about alloc/dealloc cycles using only the realloc() interface),
which is fixable by replacing realloc(p,0) calls with free(p).  libev
already works around realloc(p,0) on non-glibc targets, it may just
have to not use realloc(p,0) anywhere now as the simplest solution.
You can test for yourself whether that's the issue by doing something

void* my_realloc(void* ptr, long size) {
        return realloc(ptr, size);
    return 0;

-- Brandon

More information about the libev mailing list