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 643611 - Leak on gail_widget_get_description
Leak on gail_widget_get_description
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Accessibility
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 683317 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-03-01 18:10 UTC by Alejandro Piñeiro Iglesias (IRC: infapi00)
Modified: 2012-09-12 19:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixes the bug (4.85 KB, patch)
2012-09-11 19:21 UTC, Alejandro Piñeiro Iglesias (IRC: infapi00)
reviewed Details | Review
Fixes the bug (2.43 KB, patch)
2012-09-12 11:39 UTC, Alejandro Piñeiro Iglesias (IRC: infapi00)
committed Details | Review

Description Alejandro Piñeiro Iglesias (IRC: infapi00) 2011-03-01 18:10:53 UTC
gail_widget_get_description uses as default description the widget tooltip, and it uses gtk-widget-get-tooltip-text to get it, in this way:

      return gtk_widget_get_tooltip_text (widget);

But seeing the documentation of this method:

Returns :
	the tooltip text, or NULL. You should free the returned string with g_free() when done.

And taking into account that the description of atk_object_get_description is:

const gchar*        atk_object_get_description          (AtkObject *accessible);

is using const, atk users would not free it.

That means that a new gchar is created but no one is freeing it => leak.

An option would maintain a copy of the description as part of a private structure on GailWidget, and return this one. This should be updated when the tooltip_text property on the widget changes.
Comment 1 Matthias Clasen 2011-03-01 21:50:45 UTC
Yeah, I've noticed that as well in the drop-gail branch; I was planning to fix this and a couple of similar leaks during the drop-gail work.
Comment 2 Alejandro Piñeiro Iglesias (IRC: infapi00) 2012-09-11 17:37:30 UTC
*** Bug 683317 has been marked as a duplicate of this bug. ***
Comment 3 Alejandro Piñeiro Iglesias (IRC: infapi00) 2012-09-11 19:21:12 UTC
Created attachment 224044 [details] [review]
Fixes the bug

This patch solves the bug as I described on the comment 0. It caches the tooltip-text, and returns it instead of a new allocated string.

It adds a private struct to GtkWidgetAccessible. Eventually layer should be moved there. I didn't do that as it is somewhat off-topic for this bug, and that layer is modified in other gtk accessible objects (so some getters/setters should be required).
Comment 4 Matthias Clasen 2012-09-11 20:33:43 UTC
Review of attachment 224044 [details] [review]:

I would personally just use g_object_set_data here - makes the cleanup on finalize happen automatically...
Comment 5 Alejandro Piñeiro Iglesias (IRC: infapi00) 2012-09-12 11:39:50 UTC
Created attachment 224095 [details] [review]
Fixes the bug

Using g_object_[set/get]_data instead of adding a private structure.
Comment 6 Matthias Clasen 2012-09-12 11:54:03 UTC
Review of attachment 224095 [details] [review]:

With the fix below, looks good

::: gtk/a11y/gtkwidgetaccessible.c
@@ +121,3 @@
+  g_object_set_data (G_OBJECT (accessible),
+                     TOOLTIP_KEY,
+                     gtk_widget_get_tooltip_text (widget));

No need to manually free, if you use g_object_set_data_full (..., g_free).

And, in fact, you have to do that, otherwise you will leak the string at finalize time. The free function is used there too
Comment 7 Alejandro Piñeiro Iglesias (IRC: infapi00) 2012-09-12 18:53:20 UTC
(In reply to comment #6)
> Review of attachment 224095 [details] [review]:
> 
> With the fix below, looks good
> 
> ::: gtk/a11y/gtkwidgetaccessible.c
> @@ +121,3 @@
> +  g_object_set_data (G_OBJECT (accessible),
> +                     TOOLTIP_KEY,
> +                     gtk_widget_get_tooltip_text (widget));
> 
> No need to manually free, if you use g_object_set_data_full (..., g_free).
> 
> And, in fact, you have to do that, otherwise you will leak the string at
> finalize time. The free function is used there too

True. Sorry, I shouln't do this king of patches in a rush. Will update it soon.
Comment 8 Alejandro Piñeiro Iglesias (IRC: infapi00) 2012-09-12 19:19:59 UTC
(In reply to comment #6)
> Review of attachment 224095 [details] [review]:
> 
> With the fix below, looks good
> 
> ::: gtk/a11y/gtkwidgetaccessible.c
> @@ +121,3 @@
> +  g_object_set_data (G_OBJECT (accessible),
> +                     TOOLTIP_KEY,
> +                     gtk_widget_get_tooltip_text (widget));
> 
> No need to manually free, if you use g_object_set_data_full (..., g_free).
> 
> And, in fact, you have to do that, otherwise you will leak the string at
> finalize time. The free function is used there too

Committed after change g_object_set_data for g_object_set_data_full