From c864288c57b3c03a99bed6e36c7f38db8d7d20e2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 May 2021 14:05:53 +0200 Subject: [PATCH] glib-aux: add nm_clear_g_string() helper Since g_string_free() takes an additional argument, it's not direclty usable with nm_clear_pointer(ptr, g_string_free); As workaround, add nm_clear_g_string() helper. (cherry picked from commit 8da91cd85f0e21d1c8c9d89d20a9e5ab5d7b03ac) (cherry picked from commit 17a3d19478367536b066417fb61b94526b493684) --- shared/nm-glib-aux/nm-macros-internal.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index cc39db45ec..398079cf3a 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1103,6 +1103,18 @@ nm_clear_g_variant(GVariant **variant) return FALSE; } +static inline gboolean +nm_clear_g_string(GString **ptr) +{ + GString *s; + + if (ptr && (s = *ptr)) { + *ptr = NULL; + g_string_free(s, TRUE); + }; + return FALSE; +} + static inline gboolean nm_clear_g_cancellable(GCancellable **cancellable) {