[PATCH v3 3/7] event-test: free opaque data when removing callbacks

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

 



The pure python event loop impl has to call

  libvirt.virEventInvokeFreeCallback

to free the event opaque data from a clean stack context

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 examples/event-test.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index a1105a3..851c09b 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -107,6 +107,7 @@ class virEventLoopPure:
         self.nextTimerID = 1
         self.handles = []
         self.timers = []
+        self.cleanup = []
         self.quit = False
 
         # The event loop can be used from multiple threads at once.
@@ -178,6 +179,11 @@ class virEventLoopPure:
     def run_once(self):
         sleep = -1
         self.runningPoll = True
+
+        for opaque in self.cleanup:
+            libvirt.virEventInvokeFreeCallback(opaque)
+        self.cleanup = []
+
         try:
             next = self.next_timeout()
             debug("Next timeout due at %d" % next)
@@ -300,8 +306,9 @@ class virEventLoopPure:
         handles = []
         for h in self.handles:
             if h.get_id() == handleID:
-                self.poll.unregister(h.get_fd())
                 debug("Remove handle %d fd %d" % (handleID, h.get_fd()))
+                self.poll.unregister(h.get_fd())
+                self.cleanup.append(h.opaque)
             else:
                 handles.append(h)
         self.handles = handles
@@ -313,7 +320,9 @@ class virEventLoopPure:
         for h in self.timers:
             if h.get_id() != timerID:
                 timers.append(h)
+            else:
                 debug("Remove timer %d" % timerID)
+                self.cleanup.append(h.opaque)
         self.timers = timers
         self.interrupt()
 
-- 
2.9.3

--
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]
  Powered by Linux