From b87696990a71c8534a1476ab1e3f63c11f8feea5 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 4 Dec 2023 13:17:19 +0000 Subject: update-mime-database: Improve use of g_string_free() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing code wasn’t incorrect, but it did trigger warnings with more modern versions of GLib, because to the compiler it looked like the built string had been leaked: ``` In file included from /opt/gnome/install/include/glib-2.0/glib/giochannel.h:36, from /opt/gnome/install/include/glib-2.0/glib.h:56, from ../../source/shared-mime-info/src/update-mime-database.cpp:14: ../../source/shared-mime-info/src/update-mime-database.cpp: In function ‘void match_value_and_mask(Match*, xmlNode*, GError**)’: /opt/gnome/install/include/glib-2.0/glib/gstring.h:73:31: error: ignoring return value of ‘gchar* g_string_free_and_steal(GString*)’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 73 | g_string_free_and_steal (str)) \ | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ ../../source/shared-mime-info/src/update-mime-database.cpp:1488:17: note: in expansion of macro ‘g_string_free’ 1488 | g_string_free(parsed_value, FALSE); | ^~~~~~~~~~~~~ cc1plus: all warnings being treated as errors ``` Rearrange the code to make the ownership transfer more explicit. Signed-off-by: Philip Withnall --- src/update-mime-database.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/update-mime-database.cpp b/src/update-mime-database.cpp index c45eaff..79f5ac2 100644 --- a/src/update-mime-database.cpp +++ b/src/update-mime-database.cpp @@ -1481,11 +1481,9 @@ static void match_value_and_mask(Match *match, xmlNode *node, GError **error) } else { - match->data = parsed_value->str; match->data_length = parsed_value->len; + match->data = g_string_free(parsed_value, FALSE); match->mask = parsed_mask; - - g_string_free(parsed_value, FALSE); } if (mask) -- cgit v1.2.3