After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 763500 - Fix PrintOperation object leak
Fix PrintOperation object leak
Status: RESOLVED FIXED
Product: gnome-photos
Classification: Applications
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GNOME photos maintainer(s)
GNOME photos maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2016-03-11 15:56 UTC by Rafael Fonseca
Modified: 2016-03-16 00:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix PrintOperation object leak (1.48 KB, patch)
2016-03-11 15:57 UTC, Rafael Fonseca
none Details | Review
Fix PrintOperation leak (2.64 KB, patch)
2016-03-14 13:35 UTC, Rafael Fonseca
needs-work Details | Review
base-item: Make sure we unref the PrintOperation object (1.09 KB, patch)
2016-03-15 09:59 UTC, Debarshi Ray
committed Details | Review
base-item: Simplify getting the result of running the print operation (2.11 KB, patch)
2016-03-15 10:00 UTC, Debarshi Ray
committed Details | Review
print-setup: Take a reference on the GtkPageSetup (1.00 KB, patch)
2016-03-15 13:51 UTC, Debarshi Ray
committed Details | Review
base-item: Check for errors when printing (1.53 KB, patch)
2016-03-15 16:20 UTC, Rafael Fonseca
committed Details | Review
base-item: Check for errors when running the print operation (1.67 KB, patch)
2016-03-16 00:48 UTC, Debarshi Ray
committed Details | Review

Description Rafael Fonseca 2016-03-11 15:56:09 UTC
When printing an item, we never unref the created PrintOperation object.
Comment 1 Rafael Fonseca 2016-03-11 15:57:09 UTC
Created attachment 323720 [details] [review]
Fix PrintOperation object leak
Comment 2 Debarshi Ray 2016-03-11 18:29:29 UTC
Review of attachment 323720 [details] [review]:

Thanks for the patch, Rafael. Some quick comments:

::: src/photos-base-item.c
@@ +1468,3 @@
+                           G_CALLBACK (photos_base_item_print_operation_done),
+                           self,
+                           G_CONNECT_SWAPPED);

As far as I can tell, this clean up is not related to plugging the leak. Adding the g_clear_object should be enough. So it will be nice if you can split it into a separate patch.

About the clean up itself, I think we can go further. We can do what eog does in eog_window_print. ie., instead of connecting to the signal, just do:
  result = gtk_print_operation_run (...);
  if (result == ...)
    ...

Historical note: Most of the code originated from gnome-documents, but the printing came from eog. The joints between the two code bases shows signs of being welded together in a hurry. gnome-documents uses the "done" signal because EvPrintOperation (from evince) doesn't exactly match the GtkPrintOperation API.

@@ +1478,3 @@
  out:
   g_clear_object (&node);
+  g_clear_object (&print_op);

We should initialize print_op to NULL at the top.
Comment 3 Rafael Fonseca 2016-03-14 13:35:04 UTC
Created attachment 323870 [details] [review]
Fix PrintOperation leak

New version addressing raised points.
Comment 4 Debarshi Ray 2016-03-15 09:58:41 UTC
Review of attachment 323870 [details] [review]:

Thanks for also adding the error handling. Ideally, this should be split into 3 patches - (i) leak fix (ii) clean up (iii) error handling.
Comment 5 Debarshi Ray 2016-03-15 09:59:35 UTC
Created attachment 323953 [details] [review]
base-item: Make sure we unref the PrintOperation object
Comment 6 Debarshi Ray 2016-03-15 10:00:01 UTC
Created attachment 323954 [details] [review]
base-item: Simplify getting the result of running the print operation
Comment 7 Debarshi Ray 2016-03-15 13:51:03 UTC
Created attachment 323986 [details] [review]
print-setup: Take a reference on the GtkPageSetup

This addresses a CRITICAL seen when cancelling the print dialog without selecting any printer. Eog (eog-print-image-setup.c) doesn't suffer from this because it doesn't unref the member pointers during destruction.
Comment 8 Rafael Fonseca 2016-03-15 16:20:16 UTC
Created attachment 324023 [details] [review]
base-item: Check for errors when printing
Comment 9 Debarshi Ray 2016-03-16 00:47:34 UTC
Review of attachment 324023 [details] [review]:

::: src/photos-base-item.c
@@ +1465,3 @@
   if (print_res == GTK_PRINT_OPERATION_RESULT_APPLY)
     photos_selection_controller_set_selection_mode (self->priv->sel_cntrlr, FALSE);
+  else if (print_res == GTK_PRINT_OPERATION_RESULT_ERROR && error != NULL)

We only need to check either the print_res or the error. No need to check both.
Comment 10 Debarshi Ray 2016-03-16 00:48:32 UTC
Created attachment 324067 [details] [review]
base-item: Check for errors when running the print operation

Fixed and pushed. Also tweaked the commit message to add the prefix.