[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master c3b5355 2/2: Suppress leak detector in some cases
From: |
Philipp Stephani |
Subject: |
master c3b5355 2/2: Suppress leak detector in some cases |
Date: |
Sat, 1 Aug 2020 08:31:01 -0400 (EDT) |
branch: master
commit c3b53559965a4c6f48274c3cbcb43eb6ef23ae14
Author: Philipp Stephani <phst@google.com>
Commit: Philipp Stephani <phst@google.com>
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.
---
configure.ac | 3 ++-
src/buffer.c | 7 +++++++
src/data.c | 7 +++++++
src/emacs-module.c | 18 +++++++++++++++++-
4 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 148c50e..b4674e3 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 f1cb4d5..3456a46 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -28,6 +28,10 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. */
#include <stdlib.h>
#include <unistd.h>
+#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H
+#include <sanitizer/lsan_interface.h>
+#endif
+
#include <verify.h>
#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 1db0a98..c261e8e 100644
--- a/src/data.c
+++ b/src/data.c
@@ -23,6 +23,10 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. */
#include <math.h>
#include <stdio.h>
+#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H
+#include <sanitizer/lsan_interface.h>
+#endif
+
#include <byteswap.h>
#include <count-one-bits.h>
#include <count-trailing-zeros.h>
@@ -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 ac9ac82..8d06a24 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 <stdlib.h>
#include <time.h>
+#ifdef HAVE_SANITIZER_LSAN_INTERFACE_H
+#include <sanitizer/lsan_interface.h>
+#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);