diff options
author | Simon McVittie <smcv@collabora.com> | 2021-01-29 19:11:11 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2021-01-29 20:28:26 +0000 |
commit | 6c7d9e0389ca459ae530f8c0bdac48411827fdba (patch) | |
tree | e24d8a6378876168e524a6ded1a149a5e8d5659e | |
parent | 766295dfb757cd6e5a4c44c6776c89455191f204 (diff) | |
download | glib-6c7d9e0389ca459ae530f8c0bdac48411827fdba.tar.gz |
glib-private: Add wrappers for telling AddressSanitizer to ignore leaks
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | glib/glib-private.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/glib/glib-private.h b/glib/glib-private.h index c2e7fd401..8de380d12 100644 --- a/glib/glib-private.h +++ b/glib/glib-private.h @@ -33,7 +33,50 @@ */ #define _GLIB_ADDRESS_SANITIZER +#include <sanitizer/lsan_interface.h> + +#endif + +/* + * g_ignore_leak: + * @p: any pointer + * + * Tell AddressSanitizer and similar tools that if the object pointed to + * by @p is leaked, it is not a problem. Use this to suppress memory leak + * reports when a potentially unreachable pointer is deliberately not + * going to be deallocated. + */ +static inline void +g_ignore_leak (gconstpointer p) +{ +#ifdef _GLIB_ADDRESS_SANITIZER + if (p != NULL) + __lsan_ignore_object (p); +#endif +} + +/* + * g_ignore_strv_leak: + * @strv: (nullable) (array zero-terminated=1): an array of strings + * + * The same as g_ignore_leak(), but for the memory pointed to by @strv, + * and for each element of @strv. + */ +static inline void +g_ignore_strv_leak (GStrv strv) +{ +#ifdef _GLIB_ADDRESS_SANITIZER + gchar **item; + + if (strv) + { + g_ignore_leak (strv); + + for (item = strv; *item != NULL; item++) + g_ignore_leak (*item); + } #endif +} GMainContext * g_get_worker_context (void); gboolean g_check_setuid (void); |