At 2012-06-19 20:27:55,"Marc Lehmann" <[email protected]> wrote:
>The debian manpage is explicit though:
>
>   if size is equal to zero, and ptr is not NULL, then the call is
>   equivalent to free(ptr)
>
After doing some research, I think the issue is not about realloc(ptr, 0), it's 
about realloc(NULL, 0). According to C99 standard,        malloc()
        If the size of the space requested is zero, the behavior is 
implementation-defined.

        realloc()
        If ptr is null, the realloc function behaves like the malloc function 
for the specified size.According to glibc,        If n is zero, malloc returns 
a minumum-sized chunk. (The minimum
        size is 16 bytes on most 32bit systems, and 24 or 32 bytes on 64bit
        systems.)

And, just adding some trace to libev, we can find between ev_loop_new() and 
ev_loop_destroy(), several ev_realloc_emual(NULL, 0), by default realloc(NULL, 
0) was triggered. This can explain where the memory leaks are from. And it's 
better for libev to deal with this situation.
        ev_realloc_emul: ptr (nil), size 764, return 0x94ef008
        ev_realloc_emul: ptr (nil), size 768, return 0x94ef308
        ev_realloc_emul: ptr 0x94ef308, size 0, return (nil)
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef308
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef318
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef328
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef338
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef348
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef358
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef368
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef378
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef388
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef398
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef3a8
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef3b8
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef3c8
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef3d8
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef3e8
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef3f8
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef408
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef418
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef428
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef438
        ev_realloc_emul: ptr (nil), size 0, return 0x94ef448
        ev_realloc_emul: ptr 0x94ef008, size 0, return (nil)


----------
ylfroy

_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to