Skip to content

Commit 0bd4ad2

Browse files
committed
Improve multiple issues, leaks, improve instrumentation with valgrind, allow python to use debug mode for better debugging as a dependency.
1 parent d033e2e commit 0bd4ad2

File tree

15 files changed

+137
-70
lines changed

15 files changed

+137
-70
lines changed

cmake/CompileOptions.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ set(DEFAULT_INCLUDE_DIRECTORIES)
6868
# Libraries
6969
#
7070

71+
# Valgrind
72+
if(OPTION_TEST_MEMORYCHECK)
73+
set(MEMORYCHECK_COMPILE_DEFINITIONS
74+
"__MEMORYCHECK__=1"
75+
)
76+
else()
77+
set(MEMORYCHECK_COMPILE_DEFINITIONS)
78+
endif()
79+
7180
# ThreadSanitizer is incompatible with AddressSanitizer and LeakSanitizer
7281
if(OPTION_BUILD_THREAD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
7382
set(SANITIZER_LIBRARIES -ltsan)
@@ -136,6 +145,7 @@ set(DEFAULT_COMPILE_DEFINITIONS
136145
LOG_POLICY_FORMAT_PRETTY=${LOG_POLICY_FORMAT_PRETTY_VALUE}
137146
REFLECT_MEMORY_TRACKER=${REFLECT_MEMORY_TRACKER_VALUE}
138147
SYSTEM_${SYSTEM_NAME_UPPER}
148+
${MEMORYCHECK_COMPILE_DEFINITIONS}
139149
${SANITIZER_COMPILE_DEFINITIONS}
140150
)
141151

docker-compose.test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ services:
2424
image: metacall/core:deps
2525
build:
2626
args:
27+
METACALL_BUILD_TYPE: ${METACALL_BUILD_TYPE}
2728
METACALL_INSTALL_OPTIONS: base python ruby netcore7 nodejs typescript file rpc wasm java c cobol go rust rapidjson funchook swig pack backtrace sandbox ${METACALL_BUILD_COVERAGE} # clangformat v8rep51
2829
dev:
2930
image: metacall/core:dev

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ services:
3030
METACALL_BASE_IMAGE: $METACALL_BASE_IMAGE
3131
METACALL_PATH: $METACALL_PATH
3232
METACALL_TOOLS_PATH: $METACALL_PATH/tools
33+
METACALL_BUILD_TYPE: $METACALL_BUILD_TYPE
3334
METACALL_INSTALL_OPTIONS: base python ruby nodejs typescript file rpc rapidjson funchook swig pack backtrace # clangformat v8rep51 coverage
3435
environment:
3536
DEBIAN_FRONTEND: noninteractive

source/cli/metacallcli/source/application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ bool application::load_path(const char *path, void **handle)
337337

338338
if (plugin_path == NULL || plugin_extension_handle == NULL)
339339
{
340-
return NULL;
340+
return false;
341341
}
342342

343343
/* Define the cli plugin path as string (core plugin path plus the subpath) */

source/dynlink/source/dynlink_impl_beos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int dynlink_impl_interface_unload_beos(dynlink handle, dynlink_impl impl)
9494
{
9595
(void)handle;
9696

97-
#if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
97+
#if defined(__MEMORYCHECK__) || defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
9898
/* Disable dlclose when running with address sanitizer in order to maintain stacktraces */
9999
(void)impl;
100100
return 0;

source/dynlink/source/dynlink_impl_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ int dynlink_impl_interface_unload_unix(dynlink handle, dynlink_impl impl)
114114
{
115115
(void)handle;
116116

117-
#if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
118-
/* Disable dlclose when running with address sanitizer in order to maintain stacktraces */
117+
#if defined(__MEMORYCHECK__) || defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
118+
/* Disable dlclose when running with valgrind or sanitizers in order to maintain stacktraces */
119119
(void)impl;
120120
return 0;
121121
#else

source/loaders/py_loader/source/py_loader_impl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4206,6 +4206,7 @@ void py_loader_impl_sys_path_print(PyObject *sys_path_list)
42064206

42074207
log_write("metacall", LOG_LEVEL_DEBUG, sys_path_format_str, sys_path_str);
42084208

4209+
Py_XDECREF(sys_path_str_obj);
42094210
Py_XDECREF(separator);
42104211
}
42114212
#endif

source/ports/js_port/test/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void ModulesClear()
320320
it != modules.end(); ++it)
321321
{
322322
/* Disable dlclose when running with address sanitizer in order to maintain stacktraces */
323-
#if !defined(__ADDRESS_SANITIZER__) && !defined(__THREAD_SANITIZER__) && !defined(__MEMORY_SANITIZER__)
323+
#if !defined(__MEMORYCHECK__) && !defined(__ADDRESS_SANITIZER__) && !defined(__THREAD_SANITIZER__) && !defined(__MEMORY_SANITIZER__)
324324
#if defined(JS_PORT_TEST_WIN)
325325
FreeLibrary(it->second);
326326
#elif defined(JS_PORT_TEST_UNIX)

source/serials/rapid_json_serial/source/rapid_json_serial_impl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#include <log/log.h>
1414

15+
// TODO: RapidJSON seems to be outdated, but we use it meanwhile there's a better solution.
16+
// Here's a patch for some of the bugs in the library: https://github.com/Tencent/rapidjson/issues/1928
17+
1518
#include <rapidjson/document.h>
1619
#include <rapidjson/error/en.h>
1720
#include <rapidjson/stringbuffer.h>

source/tests/metacall_python_without_env_vars_test/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ target_link_libraries(${target}
115115
${DEFAULT_LINKER_OPTIONS}
116116
)
117117

118+
if(OPTION_BUILD_ADDRESS_SANITIZER OR OPTION_BUILD_THREAD_SANITIZER)
119+
# TODO: This test leaks and I am not sure if it is a false positive or not:
120+
#
121+
# Direct leak of 18682 byte(s) in 12 object(s) allocated from:
122+
# #0 0x7fa978386bd7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
123+
# #1 0x7fa9734ddbb1 in _PyMem_RawMalloc ../Objects/obmalloc.c:101
124+
125+
# Indirect leak of 2775 byte(s) in 2 object(s) allocated from:
126+
# #0 0x7fa978386bd7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
127+
# #1 0x7fa9734ddbb1 in _PyMem_RawMalloc ../Objects/obmalloc.c:101
128+
129+
# SUMMARY: AddressSanitizer: 21457 byte(s) leaked in 14 allocation(s).
130+
#
131+
# Valgrind does not show anything:
132+
# valgrind --tool=memcheck --leak-check=full --show-leak-kinds=possibly --track-origins=yes --num-callers=500 --suppressions=../source/tests/memcheck/valgrind-python.supp ./metacall-python-without-env-vars-testd
133+
# For checking all the leaks (and including false positives), check:
134+
# valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --num-callers=500 --suppressions=../source/tests/memcheck/valgrind-python.supp ./metacall-python-without-env-vars-testd
135+
return()
136+
endif()
137+
118138
#
119139
# Define test
120140
#

0 commit comments

Comments
 (0)