From dcf3ebfe2ba56736e1fdfc575eeb26733e6702da Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sat, 28 Sep 2024 08:38:54 +0200 Subject: [PATCH 1/7] drop-down: Replace strcmp with strcmp_0 This prevents a crash in a rare scenario. --- src/gtr-drop-down-option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gtr-drop-down-option.c b/src/gtr-drop-down-option.c index bb642a5f..b8f7319d 100644 --- a/src/gtr-drop-down-option.c +++ b/src/gtr-drop-down-option.c @@ -140,7 +140,7 @@ gtr_drop_down_option_new (const char *name, const char *description) gboolean gtr_drop_down_option_equal (GtrDropDownOption *opt1, GtrDropDownOption *opt2) { - if (strcmp (opt1->name, opt2->name)) + if (g_strcmp0 (opt1->name, opt2->name)) return FALSE; return TRUE; } -- GitLab From f94f05380eb43581695294e8d4728e1ec5ea128b Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sat, 16 Nov 2024 20:55:10 +0100 Subject: [PATCH 2/7] profile: Use g_clear_pointer in finalize The former will throw a critical if the value was NULL. --- src/gtr-profile.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gtr-profile.c b/src/gtr-profile.c index d8b6cf99..36a8049e 100644 --- a/src/gtr-profile.c +++ b/src/gtr-profile.c @@ -71,16 +71,16 @@ gtr_profile_finalize (GObject *object) GtrProfile *profile = GTR_PROFILE (object); GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile); - g_free (priv->name); - g_free (priv->auth_token); - g_free (priv->author_name); - g_free (priv->author_email); - g_free (priv->language_name); - g_free (priv->language_code); - g_free (priv->charset); - g_free (priv->encoding); - g_free (priv->group_email); - g_free (priv->plural_forms); + g_clear_pointer (&priv->name, g_free); + g_clear_pointer (&priv->auth_token, g_free); + g_clear_pointer (&priv->author_name, g_free); + g_clear_pointer (&priv->author_email, g_free); + g_clear_pointer (&priv->language_name, g_free); + g_clear_pointer (&priv->language_code, g_free); + g_clear_pointer (&priv->charset, g_free); + g_clear_pointer (&priv->encoding, g_free); + g_clear_pointer (&priv->group_email, g_free); + g_clear_pointer (&priv->plural_forms, g_free); G_OBJECT_CLASS (gtr_profile_parent_class)->finalize (object); } -- GitLab From aa69794f94188847ed6f38b9707621d7c2604cb8 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sat, 16 Nov 2024 21:16:11 +0100 Subject: [PATCH 3/7] utils: Use g_autoptr for utils_help_display --- src/gtr-utils.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/gtr-utils.c b/src/gtr-utils.c index 2b4ffbee..361893ec 100644 --- a/src/gtr-utils.c +++ b/src/gtr-utils.c @@ -252,19 +252,14 @@ void gtr_utils_help_display (GtkWindow * window) { GdkDisplay *display; - GAppLaunchContext *context; + g_autoptr (GAppLaunchContext) context = NULL; display = gtk_widget_get_display (GTK_WIDGET (window)); if (display != NULL) context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (display)); - else - context = NULL; g_app_info_launch_default_for_uri_async ("help:gtranslator", context, NULL, on_uri_launch, NULL); - - if (context) - g_object_unref (context); } gchar * -- GitLab From d74c298fcb8d2cc660b76d70f2a92763027141fc Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sat, 16 Nov 2024 21:22:42 +0100 Subject: [PATCH 4/7] po: use g_autoptr on is_read_only --- src/gtr-po.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/gtr-po.c b/src/gtr-po.c index c65ca34b..76114bcc 100644 --- a/src/gtr-po.c +++ b/src/gtr-po.c @@ -385,8 +385,8 @@ static gboolean is_read_only (const gchar * filename) { gboolean ret = TRUE; /* default to read only */ - GFileInfo *info; - GFile *location; + g_autoptr (GFileInfo) info = NULL; + g_autoptr (GFile) location = NULL; location = g_file_new_for_path (filename); @@ -396,18 +396,9 @@ is_read_only (const gchar * filename) info = g_file_query_info (location, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); - g_object_unref (location); - - if (info != NULL) - { - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) - { - ret = !g_file_info_get_attribute_boolean (info, - G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); - } - g_object_unref (info); - } + if (info != NULL && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) + ret = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); return ret; } -- GitLab From 3f920ed5a059275b05af341e966d17fd9d1a183b Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sat, 16 Nov 2024 21:42:36 +0100 Subject: [PATCH 5/7] drop-down-option: Use g_clear_pointer on finalize --- src/gtr-drop-down-option.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gtr-drop-down-option.c b/src/gtr-drop-down-option.c index b8f7319d..71ea04ae 100644 --- a/src/gtr-drop-down-option.c +++ b/src/gtr-drop-down-option.c @@ -47,8 +47,8 @@ gtr_drop_down_option_finalize (GObject *object) { GtrDropDownOption *option = GTR_DROP_DOWN_OPTION (object); - g_free (option->name); - g_free (option->description); + g_clear_pointer (&option->name, g_free); + g_clear_pointer (&option->description, g_free); G_OBJECT_CLASS (gtr_drop_down_option_parent_class)->finalize (object); } -- GitLab From a38f686e0ca2d207ab20a10fd12882a1588b61f0 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sun, 17 Nov 2024 10:14:25 +0100 Subject: [PATCH 6/7] header: Simplify frees in update_po_date --- src/gtr-header.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/gtr-header.c b/src/gtr-header.c index 31690eaf..54146d6f 100644 --- a/src/gtr-header.c +++ b/src/gtr-header.c @@ -673,21 +673,16 @@ set_profile_values (GtrHeader *header) static void update_po_date (GtrHeader * header) { - gchar *current_date; - gchar *current_time; - gchar *new_date; + g_autofree char *current_date; + g_autofree char *current_time; + g_autofree char *new_date; current_date = gtr_utils_get_current_date (); current_time = gtr_utils_get_current_time (); new_date = g_strconcat (current_date, " ", current_time, NULL); - g_free (current_date); - g_free (current_time); - gtr_header_set_po_date (header, new_date); - - g_free (new_date); } static void -- GitLab From 162fe6bba66c91c9b2dc7056ef28e48857d2bc8a Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Sun, 17 Nov 2024 11:54:30 +0100 Subject: [PATCH 7/7] header: Use g_set_str for first_year first_year uses g_autofree and a free lines above the value could have been set already. --- src/gtr-header.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gtr-header.c b/src/gtr-header.c index 54146d6f..a0eaf043 100644 --- a/src/gtr-header.c +++ b/src/gtr-header.c @@ -773,7 +773,7 @@ update_comments (GtrHeader *header, const gchar *comments) if (*search != '\0' && strcmp (search, current_year) != 0) { - first_year = g_strdup (search); + g_set_str (&first_year, search); g_free (search); break; } -- GitLab