From 5e448f23390055b69d3cbf1fb70b4c0ebda91bf2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 24 Jun 2021 11:23:18 +0200 Subject: [PATCH] glib-aux/trivial: add code comment to nm_g_source_destroy_and_unref() about g_source_destroy() I think this is non-obvious API, and should be pointed out. As we don't really have a good place for this comment, the place is a bit unmotivated. Still, add a comment. --- src/libnm-glib-aux/nm-shared-utils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 2317584de0..c73110f6c3 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -1610,6 +1610,19 @@ nm_g_variant_builder_add_sv_str(GVariantBuilder *builder, const char *key, const static inline void nm_g_source_destroy_and_unref(GSource *source) { + /* Note that calling g_source_destroy() on a currently attached source, + * will destroy the user-data of the callback right away (and not only + * during the last g_source_unref()). + * + * It also means, that if the user data itself has the reference to the + * source, then this will lead to crash: + * + * g_source_destroy(user_data->my_source); + * // ups, user_data was destroyed (if source was attached). + * g_source_unref(user_data->my_source); + * + * nm_g_source_destroy_and_unref() and nm_clear_g_source_inst() does not + * suffer from this problem. */ g_source_destroy(source); g_source_unref(source); }