[gnome-desktop] gnome-xkb-info: Fix memory leak
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop] gnome-xkb-info: Fix memory leak
- Date: Sun, 16 Sep 2012 22:37:44 +0000 (UTC)
commit c5ec270b42221c8ec6e6e62a1e3348220b266068
Author: Rui Matos <tiagomatos gmail com>
Date: Mon Sep 17 00:00:02 2012 +0200
gnome-xkb-info: Fix memory leak
We need to free the current iso639Id string when it doesn't replace a
previous one in the hash table.
https://bugzilla.gnome.org/show_bug.cgi?id=684140
libgnome-desktop/gnome-xkb-info.c | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/libgnome-desktop/gnome-xkb-info.c b/libgnome-desktop/gnome-xkb-info.c
index 7a58155..388b1f6 100644
--- a/libgnome-desktop/gnome-xkb-info.c
+++ b/libgnome-desktop/gnome-xkb-info.c
@@ -341,7 +341,7 @@ parse_start_element (GMarkupParseContext *context,
}
}
-static void
+static gboolean
maybe_replace (GHashTable *table,
gchar *key,
Layout *new_layout)
@@ -358,6 +358,8 @@ maybe_replace (GHashTable *table,
replace = strlen (new_layout->description) < strlen (layout->description);
if (replace)
g_hash_table_replace (table, key, new_layout);
+
+ return replace;
}
static void
@@ -413,6 +415,8 @@ parse_end_element (GMarkupParseContext *context,
}
else if (strcmp (element_name, "iso639Id") == 0)
{
+ gboolean replaced = FALSE;
+
if (!priv->current_parser_iso639Id)
{
g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
@@ -421,12 +425,13 @@ parse_end_element (GMarkupParseContext *context,
}
if (priv->current_parser_layout)
- maybe_replace (priv->layouts_by_iso639,
- priv->current_parser_iso639Id, priv->current_parser_layout);
+ replaced = maybe_replace (priv->layouts_by_iso639,
+ priv->current_parser_iso639Id, priv->current_parser_layout);
else if (priv->current_parser_variant)
- maybe_replace (priv->layouts_by_iso639,
- priv->current_parser_iso639Id, priv->current_parser_variant);
- else
+ replaced = maybe_replace (priv->layouts_by_iso639,
+ priv->current_parser_iso639Id, priv->current_parser_variant);
+
+ if (!replaced)
g_free (priv->current_parser_iso639Id);
priv->current_parser_iso639Id = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]