[glib: 1/4] glib-private: Add begin/end ignore leak functions for AddressSanitizer
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/4] glib-private: Add begin/end ignore leak functions for AddressSanitizer
- Date: Wed, 3 Nov 2021 15:42:21 +0000 (UTC)
commit 59ea3c53bdfb9e5a5f0c5f71e85f6346b121fae4
Author: Philip Withnall <pwithnall endlessos org>
Date: Mon Sep 27 13:12:31 2021 +0100
glib-private: Add begin/end ignore leak functions for AddressSanitizer
These just wrap the `__lsan_enable()` and `__lsan_disable()` functions
from the AddressSanitizer client API. They’re useful in situations where
the intended-to-be-leaked memory is being allocated in third-party code,
such as xdgmime. We can’t patch that code to call `g_ignore_leak()`.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #2310
glib/glib-private.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
---
diff --git a/glib/glib-private.h b/glib/glib-private.h
index 8de380d12..d00f02c04 100644
--- a/glib/glib-private.h
+++ b/glib/glib-private.h
@@ -78,6 +78,37 @@ g_ignore_strv_leak (GStrv strv)
#endif
}
+/*
+ * g_begin_ignore_leaks:
+ *
+ * Tell AddressSanitizer and similar tools to ignore all leaks from this point
+ * onwards, until g_end_ignore_leaks() is called.
+ *
+ * Try to use g_ignore_leak() where possible to target deliberate leaks more
+ * specifically.
+ */
+static inline void
+g_begin_ignore_leaks (void)
+{
+#ifdef _GLIB_ADDRESS_SANITIZER
+ __lsan_disable ();
+#endif
+}
+
+/*
+ * g_end_ignore_leaks:
+ *
+ * Start ignoring leaks again; this must be paired with a previous call to
+ * g_begin_ignore_leaks().
+ */
+static inline void
+g_end_ignore_leaks (void)
+{
+#ifdef _GLIB_ADDRESS_SANITIZER
+ __lsan_enable ();
+#endif
+}
+
GMainContext * g_get_worker_context (void);
gboolean g_check_setuid (void);
GMainContext * g_main_context_new_with_next_id (guint next_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]