From f1447220f7e29c0eeedd90c3f3bc758125fa1b10 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 May 2017 03:05:55 -0400 Subject: [PATCH] plugin-so.c: use BABELTRACE_NO_DLCLOSE env. var. to avoid dlclose() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit See new comment in plugin-so.c. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- lib/plugin/plugin-so.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index ab2f4860..4c390b76 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -138,10 +138,24 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) } if (shared_lib_handle->module) { - if (!g_module_close(shared_lib_handle->module)) { - printf_error("Module close error: %s\n", - g_module_error()); +#ifndef NDEBUG + /* + * Valgrind shows incomplete stack traces when + * dynamically loaded libraries are closed before it + * finishes. Use the BABELTRACE_NO_DLCLOSE in a debug + * build to avoid this. + */ + const char *var = getenv("BABELTRACE_NO_DLCLOSE"); + + if (!var || strcmp(var, "1") != 0) { +#endif + if (!g_module_close(shared_lib_handle->module)) { + printf_error("Module close error: %s\n", + g_module_error()); + } +#ifndef NDEBUG } +#endif } if (shared_lib_handle->path) { -- 2.34.1