From 8493e8649de611b855ac6e0516d78878e3806244 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 6 Feb 2022 12:28:18 +0200 Subject: [PATCH] mu-utils: try g_autoptr/g_autofree It's useful, but let's if it works for all targets. --- lib/utils/mu-utils.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/utils/mu-utils.cc b/lib/utils/mu-utils.cc index 8516388b..e87fc020 100644 --- a/lib/utils/mu-utils.cc +++ b/lib/utils/mu-utils.cc @@ -131,8 +131,8 @@ Mu::utf8_flatten(const char* str) std::string Mu::utf8_clean(const std::string& dirty) { - GString* gstr = g_string_sized_new(dirty.length()); - auto cstr = mu_str_utf8ify(dirty.c_str()); + g_autoptr(GString) gstr = g_string_sized_new(dirty.length()); + g_autofree char *cstr = mu_str_utf8ify(dirty.c_str()); for (auto cur = cstr; cur && *cur; cur = g_utf8_next_char(cur)) { const gunichar uc = g_utf8_get_char(cur); @@ -142,9 +142,7 @@ Mu::utf8_clean(const std::string& dirty) g_string_append_unichar(gstr, uc); } - g_free(cstr); std::string clean(gstr->str, gstr->len); - g_string_free(gstr, TRUE); clean.erase(0, clean.find_first_not_of(" ")); clean.erase(clean.find_last_not_of(" ") + 1); // remove trailing space