printoperation: fix case where operation may complete multiple twice
authorMichael Catanzaro <mcatanzaro@redhat.com>
Tue, 26 Sep 2023 23:47:01 +0000 (18:47 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 28 Sep 2023 00:42:45 +0000 (20:42 -0400)
If we are the final backend, then after removing ourselves there is no
backend remaining. We will schedule the idle even if it has already been
scheduled. This idle is required to run exactly once and executing it
twices results in a double free that crashes loupe when printing. It
also causes the user callback to execute twice, which could cause
similar problems.

Fixes #6122

gtk/print/gtkprintoperation-unix.c

index db4d878e3328c0ada775139be8c2463628c6a19c..7a6fb04254f2fa14f9ed52767591a57b541d4ed7 100644 (file)
@@ -1135,7 +1135,10 @@ printer_list_done_cb (GtkPrintBackend *backend,
   gtk_print_backend_destroy (backend);
   g_object_unref (backend);
 
-  if (finder->backends == NULL)
+  /* If there are no more backends left after removing ourselves from the list
+   * above, then we're finished.
+   */
+  if (finder->backends == NULL && !finder->found_printer)
     g_idle_add (find_printer_idle, finder);
 }