Couple of bugs

Steve Grubb sgrubb at redhat.com
Mon Feb 23 15:04:56 CET 2009


On Sunday 22 February 2009 01:53:39 pm Brandon Black wrote:
> The invalid free is because you're calling ev_loop_destroy on the
> default loop.  Check the docs for ev_default_loop(),
> ev_default_destroy(), ev_new_loop(), and ev_destroy_loop().

OK, switching to ev_default_destroy solves most of the leaks.


> The "leak" isn't really a leak.

Maybe not a leak in that it grows over time, but its an indication that 
shutdown wasn't as clean as I would like. :)


> It's a data structure global to libev that's allocated at startup and never
> freed, but it doesn't leak. 


This can be fixed by using a destructor (which is valid from gcc 2.7 and 
later). The following patch allows valgrind to run cleanly.

-Steve


diff -urp libev.orig/ev.c libev/ev.c
--- libev.orig/ev.c	2009-02-23 08:58:44.000000000 -0500
+++ libev/ev.c	2009-02-23 08:57:21.000000000 -0500
@@ -1397,6 +1397,13 @@ loop_init (EV_P_ unsigned int flags)
     }
 }
 
+#if defined(__GNUC__) && __GNUC__ >= 3
+static __attribute__ ((destructor)) void fini_lib(void)
+{
+	free(signals);
+}
+#endif
+
 static void noinline
 loop_destroy (EV_P)
 {



More information about the libev mailing list