Skip to content

Commit

Permalink
DISPATCH-1962 Make LSan suppressions more targeted and specific (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiridanek authored Mar 19, 2021
1 parent 1625d83 commit c6ea12e
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
-DCONSOLE_INSTALL=OFF
-DUSE_BWRAP=ON
-DRUNTIME_CHECK=${{matrix.runtimeCheck}}
-DSANITIZE_3RD_PARTY=ON
CCACHE_BASEDIR: ${{github.workspace}}
CCACHE_DIR: ${{github.workspace}}/.ccache
Expand Down
20 changes: 19 additions & 1 deletion cmake/RuntimeChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,27 @@ elseif(RUNTIME_CHECK STREQUAL "asan")
message(FATAL_ERROR "libubsan not installed - address sanitizer not available")
endif(UBSAN_LIBRARY-NOTFOUND)
message(STATUS "Runtime memory checker: gcc/clang address sanitizers")
option(SANITIZE_3RD_PARTY "Detect leaks in 3rd party libraries used by Dispatch while running tests" OFF)
if (SANITIZE_3RD_PARTY)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/tests/lsan.supp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tests/lsan.supp ${CMAKE_BINARY_DIR}/tests/lsan.supp
DEPENDS ${CMAKE_SOURCE_DIR}/tests/lsan.supp
VERBATIM)
else (SANITIZE_3RD_PARTY)
# Append wholesale library suppressions
# this is necessary if target system does not have debug symbols for these libraries installed
# and therefore the more specific suppressions do not match
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/tests/lsan.supp
COMMAND bash -c 'cat ${CMAKE_SOURCE_DIR}/tests/lsan.supp ${CMAKE_SOURCE_DIR}/tests/lsan_3rdparty.supp > ${CMAKE_BINARY_DIR}/tests/lsan.supp'
DEPENDS ${CMAKE_SOURCE_DIR}/tests/lsan.supp ${CMAKE_SOURCE_DIR}/tests/lsan_3rdparty.supp)
endif ()
add_custom_target(generate_lsan.supp ALL
DEPENDS ${CMAKE_BINARY_DIR}/tests/lsan.supp)
set(SANITIZE_FLAGS "-g -fno-omit-frame-pointer -fsanitize=address,undefined")
set(RUNTIME_ASAN_ENV_OPTIONS "detect_leaks=true suppressions=${CMAKE_SOURCE_DIR}/tests/asan.supp")
set(RUNTIME_LSAN_ENV_OPTIONS "suppressions=${CMAKE_SOURCE_DIR}/tests/lsan.supp")
set(RUNTIME_LSAN_ENV_OPTIONS "suppressions=${CMAKE_BINARY_DIR}/tests/lsan.supp")

elseif(RUNTIME_CHECK STREQUAL "tsan")
assert_has_sanitizers()
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<exclude>**/tsan.supp</exclude>
<exclude>**/asan.supp</exclude>
<exclude>**/lsan.supp</exclude>
<exclude>**/lsan_3rdparty.supp</exclude>
<exclude>**/*.json.in</exclude>
<exclude>**/*.json</exclude>
<exclude>**/*.svg</exclude>
Expand Down
78 changes: 70 additions & 8 deletions tests/lsan.supp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ leak:qd_policy_c_counts_alloc
leak:qd_policy_open_fetch_settings
leak:qdr_error_description

# to be triaged; unit_tests
leak:http-libwebsockets.c

# to be triaged; pretty much all tests
leak:^IoAdapter_init$

# to be triaged; system_tests_http
leak:^callback_healthz$
leak:^callback_metrics$

# to be triaged; system_tests_http1_adaptor
leak:^pn_condition$
leak:^pn_raw_connection$
leak:^pgetaddrinfo$

# to be triaged; system_tests_link_routes
leak:^pni_init_default_logger$

# Ignore test code
leak:run_unit_tests.c

# DISPATCH-1844 - shutdown leak
leak:sys_mutex

Expand All @@ -23,15 +44,56 @@ leak:_ctypes_alloc_format_string
leak:__strdup

####
#### Miscellaneous 3rd party libraries, test code, etc:
#### Miscellaneous 3rd party libraries:
####

leak:*libpython*
leak:*libwebsockets*
leak:*python2*
### Python

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

# Ignore test code
leak:run_unit_tests.c
# the PyMalloc mechanism is incompatible with Valgrind, it must be disabled or reported "leaks" must be suppressed
# https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug_python.html#debug-version-of-python-memory-alloc-label
leak:^PyMem_Malloc$
leak:^PyMem_Calloc$
leak:^_PyObject_GC_Resize$
# Python uses these alloc functions if you define PYTHONDEVMODE=1
leak:^_PyMem_DebugRawAlloc$
leak:^_PyMem_DebugRawRealloc$
# All the rest
leak:^list_append$
leak:^list_resize$
leak:^_PyBytes_Resize$
leak:^resize_compact$
leak:^unicode_resize$
# Python 2.7
leak:^PyString_FromStringAndSize$
leak:^PyString_FromString$
leak:^PyObject_Realloc$
leak:^_PyObject_GC_Malloc$
leak:^_PyString_Resize$
leak:^PyUnicodeUCS4_FromUnicode$
leak:^PyList_Append$
leak:^PyList_New$

### Qpid Proton

# Proton suppressions taken from Proton's lsan.supp
# this appears in system_tests_open_properties:
leak:^pni_data_grow$
leak:^pn_buffer$
leak:^pn_buffer_ensure$
# this appears in system_tests_http1_adaptor:
leak:^pn_string_grow$
leak:^pn_object_new$
leak:^pn_list$
leak:^pni_record_create$

### libwebsockets

leak:/libwebsockets.so

### CMake will append .so 3rd party suppressions here, unless disabled:
4 changes: 4 additions & 0 deletions tests/lsan_3rdparty.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 3rd party lsan suppressions

leak:/libpython2.*.so
leak:/libpython3.*.so

0 comments on commit c6ea12e

Please sign in to comment.