[libvirt] [libvirt-glib 3/3] glib: Don't leak GIOChannel when destroying IO handle

Christophe Fergeau cfergeau at redhat.com
Tue Jan 28 13:08:28 UTC 2014


gvir_event_handle_add() creates a GIOChannel in order to watch the fd it
was given for changes.
gvir_event_handle_remove() is freeing all the resources allocated by
gvir_event_handle_add() except for this GIOChannel. This commit adds
the needed g_io_channel_unref() call to gvir_event_handle_remove()
---
 libvirt-glib/libvirt-glib-event.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c
index adcc2fe..f8227d6 100644
--- a/libvirt-glib/libvirt-glib-event.c
+++ b/libvirt-glib/libvirt-glib-event.c
@@ -298,6 +298,10 @@ gvir_event_handle_remove(int watch)
         data->events = 0;
     }
 
+    g_warn_if_fail(data->channel != NULL);
+    g_io_channel_unref(data->channel);
+    data->channel = NULL;
+
     /* since the actual watch deletion is done asynchronously, a handle_update call may
      * reschedule the watch before it's fully deleted, that's why we need to mark it as
      * 'removed' to prevent reuse
-- 
1.8.5.3




More information about the libvir-list mailing list