From f7f091a2e6d3167fed4e1063dea266cdfff3ab55 Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 19 Mar 2020 21:21:17 +0000 Subject: deploy: 6259d4ee6c06cc6ae4ce07484b75f7d327a6a52a --- glibc.html | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 glibc.html (limited to 'glibc.html') diff --git a/glibc.html b/glibc.html new file mode 100644 index 0000000..5f72db8 --- /dev/null +++ b/glibc.html @@ -0,0 +1,249 @@ + + + + + + glibc - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + +
+
+

glibc

+

malloc tracer mtrace(3)

+

Trace memory allocation and de-allocation to detect memory leaks. +Need to call mtrace(3) to install the tracing hooks.

+

If we can't modify the binary to call mtrace we can create a small shared +library and pre-load it.

+
// libmtrace.c
+#include <mcheck.h>
+__attribute__((constructor))  static void init_mtrace() { mtrace(); }
+
+

Compile as:

+
gcc -shared -fPIC -o libmtrace.so libmtrace.c
+
+

To generate the trace file run:

+
export MALLOC_TRACE=<file>
+LD_PRELOAD=./libmtrace.so <binary>
+
+

Note: If MALLOC_TRACE is not set mtrace won't install tracing hooks.

+

To get the results of the trace file:

+
mtrace <binary> $MALLOC_TRACE
+
+

malloc check mallopt(3)

+

Configure action when glibc detects memory error.

+
export MALLOC_CHECK_=<N>
+
+

Useful values:

+
1   print detailed error & continue
+3   print detailed error + stack trace + memory mappings & abort
+7   print simple error message + stack trace + memory mappings & abort
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3