GNOME Bugzilla – Bug 780234
gtk_print_job_set_page_ranges() has unclear ownership transfer
Last modified: 2017-03-24 15:46:02 UTC
gtk_print_job_set_page_ranges(GtkPrintJob *job, GtkPageRange *ranges, gint_ranges) takes ownership of the GtkPageRange array, but this is not mentioned in the documentation. The pointer is copied to job->priv->page_ranges and the array is later freed by gtk_print_job_finalize(). Compare gtk_print_settings_set_page_ranges(), which is documented exactly the same, but does not take ownership. If gtk_print_job_set_page_ranges() is called more than once, the ownership issue becomes really confusing, because gtk_print_job_set_page_ranges() does not free a previously stored array.
Created attachment 348217 [details] [review] patch: printjob: Clarify array ownership in gtk_print_job_set_page_ranges() This patch clarifies the ownership transfer. I'm not sure if it's the right way to do it, though. I've not found any other functions with a transfer annotation on an input parameter.
Review of attachment 348217 [details] [review]: The commit message should certainly mention that a g_free call is added to fix a memory leak when set_page_ranges is used repeatedly. ::: gtk/gtkprintjob.c @@ +795,3 @@ gint n_ranges) { + g_free(job->priv->page_ranges); space before (, please
Created attachment 348258 [details] [review] patch: printjob: Clarify array ownership in gtk_print_job_set_page_ranges() Updated patch.
Review of attachment 348258 [details] [review]: looks good now, thanks
Comment on attachment 348258 [details] [review] patch: printjob: Clarify array ownership in gtk_print_job_set_page_ranges() Pushed to the master branch