[gtranslator: 4/5] Improve memory management in nplural inconsistency check
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator: 4/5] Improve memory management in nplural inconsistency check
- Date: Thu, 2 Jun 2022 15:38:15 +0000 (UTC)
commit a8a77afc619a6cd0ae8e695b88155ae76a1946fd
Author: Daniel GarcĂa Moreno <dani danigm net>
Date: Thu Jun 2 17:25:57 2022 +0200
Improve memory management in nplural inconsistency check
This patch removes some memory leaks in the handle_file_is_inconsistent
function.
src/gtr-po.c | 2 ++
src/gtr-tab.c | 27 ++++++++++++++++++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/src/gtr-po.c b/src/gtr-po.c
index 75ebe49a..a894189d 100644
--- a/src/gtr-po.c
+++ b/src/gtr-po.c
@@ -1442,6 +1442,8 @@ gtr_po_consistent_with_profile (GtrPo * po)
gtr_profile_get_plural_forms (profile)
);
+ g_object_unref (prof_manager);
+
return profile_nplurals == po_header_nplurals;
}
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 5e7cb5fb..1547300c 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -269,15 +269,32 @@ handle_file_is_inconsistent (GtrPo *po, GtrTab *tab)
GtrTabPrivate *priv = gtr_tab_get_instance_private (tab);
GtrProfileManager *manager = gtr_profile_manager_get_default ();
GtrProfile *active_profile = gtr_profile_manager_get_active_profile (manager);
- const gchar* profile_name = gtr_profile_get_name (active_profile);
-
- gchar* info_msg_primary = g_strdup_printf ("File is not consistent with profile %s",profile_name);
- gchar *filename = g_file_get_path (gtr_po_get_location (po));
- gchar* info_msg_secondary = g_strdup_printf ("Kindly go to preferences and select a profile with
consistent nplurals values as this file %s",filename);
+ const char *profile_name = gtr_profile_get_name (active_profile);
+ int profile_nplurals = -1;
+ int po_nplurals = -1;
+
+ g_autofree char *info_msg_primary = NULL;
+ g_autofree char *info_msg_secondary = NULL;
+ g_autofree char *filename = NULL;
+ g_autoptr (GFile) po_file = gtr_po_get_location (po);
+
+ filename = g_file_get_path (po_file);
+ po_nplurals = gtr_header_get_nplurals (gtr_po_get_header (po));
+ profile_nplurals = parse_nplurals_header (gtr_profile_get_plural_forms (active_profile));
+
+ info_msg_primary = g_strdup_printf ("File is not consistent with profile %s", profile_name);
+ info_msg_secondary = g_strdup_printf (
+ "File nplurals: %d, is different from profile nplurals %d.\n"
+ "Kindly go to preferences and select a profile with consistent nplurals "
+ "values as this file %s.",
+ po_nplurals, profile_nplurals, filename
+ );
gtr_tab_set_info (tab, info_msg_primary, info_msg_secondary);
GtkWidget *nb = priv->trans_notebook;
gtk_widget_set_sensitive (nb, FALSE);
+
+ g_object_unref (manager);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]