[Libguestfs] [libnbd PATCH 2/4] examples: glib-main-loop: don't strand commands when gsource disappears

Eric Blake eblake at redhat.com
Tue Feb 1 19:44:48 UTC 2022


Returning 0 from a callback handler implies that we will later call
nbd_aio_command_completed(), but we weren't doing that, and our
finalize() handler instead asserts that no outstanding commands
remain.  Even when we are going to ignore a late completion (due to
the gsource already being torn down), we should still auto-retire the
command.

Fixes: 7e53d48e ("api: Allow completion callbacks to auto-retire", v0.1.9)
---
 examples/glib-main-loop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/glib-main-loop.c b/examples/glib-main-loop.c
index 9c279d39..2df27878 100644
--- a/examples/glib-main-loop.c
+++ b/examples/glib-main-loop.c
@@ -400,7 +400,7 @@ finished_read (void *vp, int *error)
   struct buffer *buffer = vp;

   if (gssrc == NULL)
-    return 0;
+    return 1; /* Nothing we can do, auto-retire the callback */

   DEBUG (gssrc, "finished_read: read completed");

@@ -446,7 +446,7 @@ finished_write (void *vp, int *error)
   struct buffer *buffer = vp;

   if (gsdest == NULL)
-    return 0;
+    return 1; /* Nothing we can do, auto-retire the callback */

   DEBUG (gsdest, "finished_write: write completed");

-- 
2.34.1




More information about the Libguestfs mailing list