From: Philippe Proulx Date: Wed, 24 May 2017 07:05:55 +0000 (-0400) Subject: plugin-so.c: use BABELTRACE_NO_DLCLOSE env. var. to avoid dlclose() X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=f1447220f7e29c0eeedd90c3f3bc758125fa1b10;p=deliverable%2Fbabeltrace.git plugin-so.c: use BABELTRACE_NO_DLCLOSE env. var. to avoid dlclose() See new comment in plugin-so.c. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index ab2f48607..4c390b76e 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) {