From: Philipp Stephani Date: Sat, 1 Aug 2020 12:13:55 +0000 (+0200) Subject: Suppress leak detector in some cases X-Git-Tag: emacs-28.0.90~6882 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c3b53559965a4c6f48274c3cbcb43eb6ef23ae14;p=emacs.git Suppress leak detector in some cases We intentionally leak some objects. Prevent the ASan leak detector from raising false alarms in these cases. * configure.ac: Search for lsan_interface.h header. * src/data.c (make_blv): Allow leaking of buffer-local values. * src/buffer.c (enlarge_buffer_text): Allow leaking of buffer text. * src/emacs-module.c (Fmodule_load, initialize_environment): Allow intentional leak of runtime and environment objects if module assertions are enabled. --- diff --git a/configure.ac b/configure.ac index 148c50e0b39..b4674e3204b 100644 --- a/configure.ac +++ b/configure.ac @@ -1740,7 +1740,8 @@ AC_CHECK_HEADERS_ONCE( sys/sysinfo.h coff.h pty.h sys/resource.h - sys/utsname.h pwd.h utmp.h util.h) + sys/utsname.h pwd.h utmp.h util.h + sanitizer/lsan_interface.h) AC_CACHE_CHECK([for ADDR_NO_RANDOMIZE], [emacs_cv_personality_addr_no_randomize], diff --git a/src/buffer.c b/src/buffer.c index f1cb4d50414..3456a46be3e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -28,6 +28,10 @@ along with GNU Emacs. If not, see . */ #include #include +#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H +#include +#endif + #include #include "lisp.h" @@ -5083,6 +5087,9 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) #else p = xrealloc (b->text->beg, new_nbytes); #endif +#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H + __lsan_ignore_object (p); +#endif if (p == NULL) { diff --git a/src/data.c b/src/data.c index 1db0a983b49..c261e8e90dd 100644 --- a/src/data.c +++ b/src/data.c @@ -23,6 +23,10 @@ along with GNU Emacs. If not, see . */ #include #include +#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H +#include +#endif + #include #include #include @@ -1784,6 +1788,9 @@ make_blv (struct Lisp_Symbol *sym, bool forwarded, set_blv_defcell (blv, tem); set_blv_valcell (blv, tem); set_blv_found (blv, false); +#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H + __lsan_ignore_object (blv); +#endif return blv; } diff --git a/src/emacs-module.c b/src/emacs-module.c index ac9ac824b7b..8d06a24210b 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -84,6 +84,10 @@ To add a new module function, proceed as follows: #include #include +#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H +#include +#endif + #include "lisp.h" #include "bignum.h" #include "dynlib.h" @@ -1095,7 +1099,16 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0, for two different runtime objects are guaranteed to be distinct, which we can use for checking the liveness of runtime pointers. */ - struct emacs_runtime *rt = module_assertions ? xmalloc (sizeof *rt) : &rt_pub; + struct emacs_runtime *rt; + if (module_assertions) + { + rt = xmalloc (sizeof *rt); +#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H + __lsan_ignore_object (rt); +#endif + } + else + rt = &rt_pub; rt->size = sizeof *rt; rt->private_members = &rt_priv; rt->get_environment = module_get_environment; @@ -1411,7 +1424,10 @@ static emacs_env * initialize_environment (emacs_env *env, struct emacs_env_private *priv) { if (module_assertions) + { env = xmalloc (sizeof *env); + __lsan_ignore_object (env); + } priv->pending_non_local_exit = emacs_funcall_exit_return; initialize_storage (&priv->storage);