summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@gnome.org>2023-12-04 13:17:19 +0000
committerPhilip Withnall <pwithnall@gnome.org>2023-12-04 13:17:19 +0000
commitb87696990a71c8534a1476ab1e3f63c11f8feea5 (patch)
treeae64a02c159b0fbed876e8fa658fefba3dfd9ac4
parentdbf2a26ee455a306fa925cb438f4a4c66c288be0 (diff)
update-mime-database: Improve use of g_string_free()
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 <pwithnall@gnome.org>
-rw-r--r--src/update-mime-database.cpp4
1 files changed, 1 insertions, 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)