Skip to content

Commit c6ea12e

Browse files
authored
DISPATCH-1962 Make LSan suppressions more targeted and specific (#1048)
1 parent 1625d83 commit c6ea12e

File tree

5 files changed

+95
-9
lines changed

5 files changed

+95
-9
lines changed

.github/workflows/build.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
-DCONSOLE_INSTALL=OFF
5454
-DUSE_BWRAP=ON
5555
-DRUNTIME_CHECK=${{matrix.runtimeCheck}}
56+
-DSANITIZE_3RD_PARTY=ON
5657
5758
CCACHE_BASEDIR: ${{github.workspace}}
5859
CCACHE_DIR: ${{github.workspace}}/.ccache

cmake/RuntimeChecks.cmake

+19-1
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,27 @@ elseif(RUNTIME_CHECK STREQUAL "asan")
106106
message(FATAL_ERROR "libubsan not installed - address sanitizer not available")
107107
endif(UBSAN_LIBRARY-NOTFOUND)
108108
message(STATUS "Runtime memory checker: gcc/clang address sanitizers")
109+
option(SANITIZE_3RD_PARTY "Detect leaks in 3rd party libraries used by Dispatch while running tests" OFF)
110+
if (SANITIZE_3RD_PARTY)
111+
add_custom_command(
112+
OUTPUT ${CMAKE_BINARY_DIR}/tests/lsan.supp
113+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tests/lsan.supp ${CMAKE_BINARY_DIR}/tests/lsan.supp
114+
DEPENDS ${CMAKE_SOURCE_DIR}/tests/lsan.supp
115+
VERBATIM)
116+
else (SANITIZE_3RD_PARTY)
117+
# Append wholesale library suppressions
118+
# this is necessary if target system does not have debug symbols for these libraries installed
119+
# and therefore the more specific suppressions do not match
120+
add_custom_command(
121+
OUTPUT ${CMAKE_BINARY_DIR}/tests/lsan.supp
122+
COMMAND bash -c 'cat ${CMAKE_SOURCE_DIR}/tests/lsan.supp ${CMAKE_SOURCE_DIR}/tests/lsan_3rdparty.supp > ${CMAKE_BINARY_DIR}/tests/lsan.supp'
123+
DEPENDS ${CMAKE_SOURCE_DIR}/tests/lsan.supp ${CMAKE_SOURCE_DIR}/tests/lsan_3rdparty.supp)
124+
endif ()
125+
add_custom_target(generate_lsan.supp ALL
126+
DEPENDS ${CMAKE_BINARY_DIR}/tests/lsan.supp)
109127
set(SANITIZE_FLAGS "-g -fno-omit-frame-pointer -fsanitize=address,undefined")
110128
set(RUNTIME_ASAN_ENV_OPTIONS "detect_leaks=true suppressions=${CMAKE_SOURCE_DIR}/tests/asan.supp")
111-
set(RUNTIME_LSAN_ENV_OPTIONS "suppressions=${CMAKE_SOURCE_DIR}/tests/lsan.supp")
129+
set(RUNTIME_LSAN_ENV_OPTIONS "suppressions=${CMAKE_BINARY_DIR}/tests/lsan.supp")
112130

113131
elseif(RUNTIME_CHECK STREQUAL "tsan")
114132
assert_has_sanitizers()

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<exclude>**/tsan.supp</exclude>
9797
<exclude>**/asan.supp</exclude>
9898
<exclude>**/lsan.supp</exclude>
99+
<exclude>**/lsan_3rdparty.supp</exclude>
99100
<exclude>**/*.json.in</exclude>
100101
<exclude>**/*.json</exclude>
101102
<exclude>**/*.svg</exclude>

tests/lsan.supp

+70-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@ leak:qd_policy_c_counts_alloc
1010
leak:qd_policy_open_fetch_settings
1111
leak:qdr_error_description
1212

13+
# to be triaged; unit_tests
14+
leak:http-libwebsockets.c
15+
16+
# to be triaged; pretty much all tests
17+
leak:^IoAdapter_init$
18+
19+
# to be triaged; system_tests_http
20+
leak:^callback_healthz$
21+
leak:^callback_metrics$
22+
23+
# to be triaged; system_tests_http1_adaptor
24+
leak:^pn_condition$
25+
leak:^pn_raw_connection$
26+
leak:^pgetaddrinfo$
27+
28+
# to be triaged; system_tests_link_routes
29+
leak:^pni_init_default_logger$
30+
31+
# Ignore test code
32+
leak:run_unit_tests.c
33+
1334
# DISPATCH-1844 - shutdown leak
1435
leak:sys_mutex
1536

@@ -23,15 +44,56 @@ leak:_ctypes_alloc_format_string
2344
leak:__strdup
2445

2546
####
26-
#### Miscellaneous 3rd party libraries, test code, etc:
47+
#### Miscellaneous 3rd party libraries:
2748
####
2849

29-
leak:*libpython*
30-
leak:*libwebsockets*
31-
leak:*python2*
50+
### Python
3251

33-
# We should be able to uncomment these once all known dispatch leaks have been fixed
34-
leak:*libqpid-proton*
52+
# these Python leaks happen even after simple Py_Initialize(); Py_Finalize();
53+
# https://bugs.python.org/issue1635741
54+
leak:^_PyObject_Realloc
55+
leak:^PyObject_Malloc$
56+
leak:^PyThread_allocate_lock$
3557

36-
# Ignore test code
37-
leak:run_unit_tests.c
58+
# the PyMalloc mechanism is incompatible with Valgrind, it must be disabled or reported "leaks" must be suppressed
59+
# https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug_python.html#debug-version-of-python-memory-alloc-label
60+
leak:^PyMem_Malloc$
61+
leak:^PyMem_Calloc$
62+
leak:^_PyObject_GC_Resize$
63+
# Python uses these alloc functions if you define PYTHONDEVMODE=1
64+
leak:^_PyMem_DebugRawAlloc$
65+
leak:^_PyMem_DebugRawRealloc$
66+
# All the rest
67+
leak:^list_append$
68+
leak:^list_resize$
69+
leak:^_PyBytes_Resize$
70+
leak:^resize_compact$
71+
leak:^unicode_resize$
72+
# Python 2.7
73+
leak:^PyString_FromStringAndSize$
74+
leak:^PyString_FromString$
75+
leak:^PyObject_Realloc$
76+
leak:^_PyObject_GC_Malloc$
77+
leak:^_PyString_Resize$
78+
leak:^PyUnicodeUCS4_FromUnicode$
79+
leak:^PyList_Append$
80+
leak:^PyList_New$
81+
82+
### Qpid Proton
83+
84+
# Proton suppressions taken from Proton's lsan.supp
85+
# this appears in system_tests_open_properties:
86+
leak:^pni_data_grow$
87+
leak:^pn_buffer$
88+
leak:^pn_buffer_ensure$
89+
# this appears in system_tests_http1_adaptor:
90+
leak:^pn_string_grow$
91+
leak:^pn_object_new$
92+
leak:^pn_list$
93+
leak:^pni_record_create$
94+
95+
### libwebsockets
96+
97+
leak:/libwebsockets.so
98+
99+
### CMake will append .so 3rd party suppressions here, unless disabled:

tests/lsan_3rdparty.supp

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 3rd party lsan suppressions
2+
3+
leak:/libpython2.*.so
4+
leak:/libpython3.*.so

0 commit comments

Comments
 (0)