[PATCH] event-test: Unregister close callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When registering a close callback, the connection refcount is increased
as the connection object is passed to the callback and hence we must
prevent deleting it too soon. However, when closing the connection, the
connection object is just unrefed. So whenever a connection with a close
callback is closed, we end up with the connection object which has
exactly one reference. Leaving the code as-is doesn't mean the end of
the world as we know it, but why give a bad example?

==14531== 288 bytes in 1 blocks are still reachable in loss record 695 of 762
==14531==    at 0x4C2BDE4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==14531==    by 0x4E9FE09: virAllocVar (viralloc.c:558)
==14531==    by 0x4EDBE45: virObjectNew (virobject.c:190)
==14531==    by 0x4F71AAC: virGetConnect (datatypes.c:116)
==14531==    by 0x4F78511: do_open (libvirt.c:1136)
==14531==    by 0x4F7B3AC: virConnectOpenAuth (libvirt.c:1481)
==14531==    by 0x4011D2: main (event-test.c:499)

(and other leaks tied to virGetConnect())

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 examples/object-events/event-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
index f872b9f..228a091 100644
--- a/examples/object-events/event-test.c
+++ b/examples/object-events/event-test.c
@@ -675,6 +675,8 @@ int main(int argc, char **argv)
             virConnectDomainEventDeregisterAny(dconn, callback8ret);
     }
 
+    virConnectUnregisterCloseCallback(dconn, connectClose);
+
     VIR_DEBUG("Closing connection");
     if (dconn && virConnectClose(dconn) < 0) {
         printf("error closing\n");
-- 
1.8.5.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]