GNOME Bugzilla – Bug 668863
gtk_enumerate_printers may not call the destroy notification callback
Last modified: 2018-05-02 15:19:00 UTC
Created attachment 206288 [details] Test program: runs fine if CUPS is started, always hangs if CUPS is stopped As the gtk_enumerate_printers() documentation says, the destroy argument is a function called when data is no longer needed. However, if - CUPS is supported by GTK, - and it is listed as the last on the list of the printing backends, - and CUPS is not installed, not running, or not configured properly, then the destroy notification callback is never called. This happens because gtk_enumerate_printers() calls list_printers_init() and if list_printers_init() fails then it just returns. list_printers_init() may fail if the print backend reports status GTK_PRINT_BACKEND_STATUS_UNAVAILABLE. If this happens, list_printers_init() removes the backend from the printer_list->backends list. If this backend is the only item in this list then printer_list->backends becomes NULL. In all other places if printer_list->backends becomes NULL (or is never initialized) then free_printer_list(printer_list) is called which calls the destroy notification callback. However, in this case this callback is not called and the function just quits. As a consequence: - if the callback is used to free the allocated memory then a memory leak occurs, - if the callback is used to notify the caller that all printers have been enumerated and the caller waits for the callback then caller hangs. I attach a simple test program which runs fine if CUPS is running but always hangs if CUPS is turned off. Here is a copy of the test session: ========================================================================= $ ./printer_hangs This program hangs if CUPS subsystem is not running correctly Enumerating your printers: Printer name: Print to File destroy_notify called destroy_notify already called, end of the program $ su Password: # /etc/init.d/cups stop Stopping cups: [ OK ] # exit $ ./printer_hangs This program hangs if CUPS subsystem is not running correctly Enumerating your printers: Printer name: Print to File destroy_notify not yet called, waiting ^C $ su Password: # /etc/init.d/cups start Starting cups: [ OK ] # exit $ ./printer_hangs This program hangs if CUPS subsystem is not running correctly Enumerating your printers: Printer name: Print to File destroy_notify called destroy_notify already called, end of the program $ ========================================================================= I have tested this on 3 different machines and the result is always the same. I have also checked the latest sources and they are same as 2.x series so I believe the behavior in 3.x series is the same. You can compile the test program with: gcc -o printer_hangs `pkg-config --cflags --libs gtk+-2.0 gtk+-unix-print-2.0` printer_hangs.c
Created attachment 206449 [details] [review] Proposed patch to fix this bug This should fix the problem. Frees the list and returs TRUE from list_printers_init() to stop the enumeration. This code is executed only if a print backend is marked as unavailable or gtk_print_backend_printer_list_is_done() returns TRUE and this is the last backend on the list of the backends. Runs fine on my computer no matter if CUPS is started or stopped. Please test, review, check my English spelling, and finally apply if you find it correct. See also: Bug 346903
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
(In reply to Matthias Clasen from comment #2) > [...] If this issue is still > important to you and still relevant with GTK+ 3.22 or master, please reopen > it and we will migrate it to gitlab. It looks like it has been fixed in 3.22 as bug 686838 but as mentioned in bug 686838 comment 7 the fix should be also backported to 2.24.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/381.