Memory leak in ev.c, the second

Alexander Klauer Alexander.Klauer at
Wed Feb 20 17:28:57 CET 2013


let's see if I get it right this time. libev maps allocation, 
reallocation, and freeing of memory to calls of one single function, set 
by ev_set_allocator(), or the default ev_realloc_emul(). The libev API 
specification mandates that the allocator function fulfils the 
requirements of realloc() as defined by C89.

Unfortunately, that is not enough to avoid memory leaks, for a call of 
the form realloc(ptr, 0) is not required to have the same semantics as a 
call to free(ptr). A C89-conformant implementation may return a unique 
non-NULL pointer which may be safely passed to free(). Therefore, the 
implementation is required to keep track of these unique pointers 
internally, whereas it is permitted to have forgotten pointers passed to 
free() once free() has returned.

The attached patch changes ev_realloc_emul() so that 
ev_realloc_emul(ptr, 0) has free(ptr) semantics in all cases.

Best regards,

Dr. Alexander Klauer
Competence Centre for High Performance Computing

Fraunhofer-Institut für Techno-
und Wirtschaftsmathematik ITWM
Fraunhofer-Platz 1
67663 Kaiserslautern
Tel.: +49 631 31600-4335
Fax : +49 631 31600-5335
Email: Alexander.Klauer at

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libev.patch
Type: text/x-patch
Size: 572 bytes
Desc: not available
URL: <>

More information about the libev mailing list