[gtk+] Fix a few memory leaks wrt to translations
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Fix a few memory leaks wrt to translations
- Date: Mon, 29 Apr 2013 01:44:55 +0000 (UTC)
commit e9f182e37a7f6e2dc339054841a3c9f930f573ed
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Apr 28 21:43:49 2013 -0400
Fix a few memory leaks wrt to translations
Pointed out in https://bugzilla.gnome.org/show_bug.cgi?id=699016
The fix here is slightly different. We make
_gtk_builder_parser_translate return a const char * instead of
a dup'ed string, and fix up the callers.
gtk/gtkbuilderparser.c | 13 ++++++-------
gtk/gtkbuilderprivate.h | 6 +++---
gtk/gtkcelllayout.c | 2 +-
gtk/gtkcomboboxtext.c | 2 +-
gtk/gtkcontainer.c | 4 ++--
gtk/gtkliststore.c | 6 +++---
gtk/gtkscale.c | 2 +-
gtk/gtkwidget.c | 2 +-
8 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index 9a4b406..6e42972 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -1015,19 +1015,19 @@ start_element (GMarkupParseContext *context,
element_name);
}
-gchar *
+const gchar *
_gtk_builder_parser_translate (const gchar *domain,
const gchar *context,
const gchar *text)
{
- const char *s;
+ const gchar *s;
if (context)
s = g_dpgettext2 (domain, context, text);
else
s = g_dgettext (domain, text);
- return g_strdup (s);
+ return s;
}
/* Called for close tags </foo> */
@@ -1128,15 +1128,14 @@ end_element (GMarkupParseContext *context,
if (prop_info->translatable && prop_info->text->len)
{
- prop_info->data = _gtk_builder_parser_translate (data->domain,
- prop_info->context,
- prop_info->text->str);
+ prop_info->data = g_strdup (_gtk_builder_parser_translate (data->domain,
+ prop_info->context,
+ prop_info->text->str));
g_string_free (prop_info->text, TRUE);
}
else
{
prop_info->data = g_string_free (prop_info->text, FALSE);
-
}
object_info->properties =
diff --git a/gtk/gtkbuilderprivate.h b/gtk/gtkbuilderprivate.h
index 9af96d9..346459c 100644
--- a/gtk/gtkbuilderprivate.h
+++ b/gtk/gtkbuilderprivate.h
@@ -148,9 +148,9 @@ gboolean _gtk_builder_flags_from_string (GType type,
const char *string,
guint *value,
GError **error);
-gchar * _gtk_builder_parser_translate (const gchar *domain,
- const gchar *context,
- const gchar *text);
+const gchar * _gtk_builder_parser_translate (const gchar *domain,
+ const gchar *context,
+ const gchar *text);
gchar * _gtk_builder_get_resource_path (GtkBuilder *builder,
const gchar *string);
gchar * _gtk_builder_get_absolute_filename (GtkBuilder *builder,
diff --git a/gtk/gtkcelllayout.c b/gtk/gtkcelllayout.c
index f9e0ce8..4f6425d 100644
--- a/gtk/gtkcelllayout.c
+++ b/gtk/gtkcelllayout.c
@@ -812,7 +812,7 @@ cell_packing_end_element (GMarkupParseContext *context,
/* translate the string */
if (parser_data->string->len && parser_data->translatable)
{
- gchar *translated;
+ const gchar *translated;
const gchar* domain;
domain = gtk_builder_get_translation_domain (parser_data->builder);
diff --git a/gtk/gtkcomboboxtext.c b/gtk/gtkcomboboxtext.c
index e09f3ef..3a3154b 100644
--- a/gtk/gtkcomboboxtext.c
+++ b/gtk/gtkcomboboxtext.c
@@ -234,7 +234,7 @@ item_end_element (GMarkupParseContext *context,
{
if (data->translatable)
{
- gchar *translated;
+ const gchar *translated;
/* FIXME: This will not use the domain set in the .ui file,
* since the parser is not telling the builder about the domain.
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 09bfffa..4a642df 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -664,8 +664,8 @@ attributes_end_element (GMarkupParseContext *context,
/* translate the string */
if (parser_data->string->len && parser_data->translatable)
{
- gchar *translated;
- const gchar* domain;
+ const gchar *translated;
+ const gchar *domain;
domain = gtk_builder_get_translation_domain (parser_data->builder);
diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c
index 467bac0..11dae3f 100644
--- a/gtk/gtkliststore.c
+++ b/gtk/gtkliststore.c
@@ -2555,9 +2555,9 @@ list_store_text (GMarkupParseContext *context,
* since the parser is not telling the builder about the domain.
* However, it will work for gtk_builder_set_translation_domain() calls.
*/
- translated = _gtk_builder_parser_translate (data->domain,
- info->context,
- string);
+ translated = g_strdup (_gtk_builder_parser_translate (data->domain,
+ info->context,
+ string));
g_free (string);
string = translated;
}
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 4f739d8..6abd82e 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -1880,7 +1880,7 @@ gtk_scale_buildable_custom_finished (GtkBuildable *buildable,
if (strcmp (tagname, "marks") == 0)
{
GSList *m;
- gchar *markup;
+ const gchar *markup;
marks_data = (MarksSubparserData *)user_data;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f2f239f..f32dab1 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -13522,7 +13522,7 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
if (i < n_actions)
{
- gchar *description;
+ const gchar *description;
if (action_data->translatable && action_data->description->len)
description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain
(builder),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]