summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-03-05 12:49:04 +0100
committerThomas Haller <thaller@redhat.com>2018-03-10 16:49:30 +0100
commitb0b5cfb7f2cc9df045cdde2c1b6add04ff86442d (patch)
tree19459e8f9b84120788810cead78e2715625b9d1c
parent14ffe6bc5515500f47984e7ce6e1d97b2eff4425 (diff)
downloadNetworkManager-b0b5cfb7f2cc9df045cdde2c1b6add04ff86442d.tar.gz
shared: add nm_g_variant_unref_floating() helper
-rw-r--r--shared/nm-utils/nm-shared-utils.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h
index ce75e76d19..122f1187bd 100644
--- a/shared/nm-utils/nm-shared-utils.h
+++ b/shared/nm-utils/nm-shared-utils.h
@@ -421,6 +421,23 @@ char *nm_utils_str_utf8safe_unescape_cp (const char *str);
char *nm_utils_str_utf8safe_escape_take (char *str, NMUtilsStrUtf8SafeFlags flags);
+static inline void
+nm_g_variant_unref_floating (GVariant *var)
+{
+ /* often a function wants to keep a reference to an input variant.
+ * It uses g_variant_ref_sink() to either increase the ref-count,
+ * or take ownership of a possibly floating reference.
+ *
+ * If the function doesn't actually want to do anything with the
+ * input variant, it still must make sure that a passed in floating
+ * reference is consumed. Hence, this helper which:
+ *
+ * - does nothing if @var is not floating
+ * - unrefs (consumes) @var if it is floating. */
+ if (g_variant_is_floating (var))
+ g_variant_unref (var);
+}
+
/*****************************************************************************/
typedef struct {