aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <[email protected]>2016-03-23 22:23:06 +0000
committerWerner Koch <[email protected]>2016-03-24 09:15:09 +0000
commit52c3606b2384f33ef30ea5ada3f187829de9dcf7 (patch)
tree4c190a7c54ddb68149dbfbaceca6ed33de0474dc
parentsyscfg: Add lock-obj-pub files for {armv5, armv6, x86_64}-musl targets (diff)
downloadlibgpg-error-52c3606b2384f33ef30ea5ada3f187829de9dcf7.tar.gz
libgpg-error-52c3606b2384f33ef30ea5ada3f187829de9dcf7.zip
Add function gpgrt_annotate_leaked_object.
* src/gpg-error.h.in: add gpgrt_annotate_leaked_object to support marking memory as non-leaked for Clang and GCC. -- This annotation can be used to mark objects as explicitly leaked such that it can be ignored in tools like LeakSanitizer. The GPGRT_HAVE_LEAK_SANITIZER macro is explicitly not undefined to support -fsanitize=leak, a user or configure script could then decide to add this macro when just -fsanitize=leak is given. Signed-off-by: Peter Wu <[email protected]> Additional changes by -wk: - But __GNUC__ guard around the entire GPGRT_HAVE_LEAK_SANITIZER detection. - Add NEWS entry. Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--NEWS1
-rw-r--r--src/gpg-error.h.in30
2 files changed, 31 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index b8d6be5..d1d21fa 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Noteworthy changes in version 1.22 (unreleased) [C17/A17/R_)
* Interface changes relative to the 1.20 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GPG_ERR_DB_CORRUPTED NEW.
+ gpgrt_annotate_leaked_object NEW inline func.
Noteworthy changes in version 1.21 (2015-12-12) [C17/A17/R0]
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index b32b4c4..f0043f3 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -246,10 +246,40 @@ typedef unsigned int gpg_error_t;
# define GPGRT_HAVE_PRAGMA_GCC_PUSH 1
#endif
+/* Detect LeakSanitizer (LSan) support for GCC and Clang based on
+ * whether AddressSanitizer (ASAN) is enabled via -fsanitize=address).
+ * Note that -fsanitize=leak just affect the linker options which
+ * cannot be detected here. In that case you have to define the
+ * GPGRT_HAVE_LEAK_SANITIZER macro manually. */
+#ifdef __GNUC__
+# ifdef __SANITIZE_ADDRESS__
+# define GPGRT_HAVE_LEAK_SANITIZER
+# elif defined(__has_feature)
+# if __has_feature(address_sanitizer)
+# define GPGRT_HAVE_LEAK_SANITIZER
+# endif
+# endif
+#endif
+
/* The new name for the inline macro. */
#define GPGRT_INLINE GPG_ERR_INLINE
+#ifdef GPGRT_HAVE_LEAK_SANITIZER
+# include <sanitizer/lsan_interface.h>
+#endif
+
+/* Mark heap objects as non-leaked memory. */
+static GPGRT_INLINE void
+gpgrt_annotate_leaked_object (const void *p)
+{
+#ifdef GPGRT_HAVE_LEAK_SANITIZER
+ __lsan_ignore_object(p);
+#else
+ (void)p;
+#endif
+}
+
/* Initialization function. */