plugin-so.c: use BABELTRACE_NO_DLCLOSE env. var. to avoid dlclose()
[babeltrace.git] / lib / plugin / plugin-so.c
index ab2f486078e9930b18416df0150e55270c313adf..4c390b76e53f8d15067876d8c41d6274732d9707 100644 (file)
@@ -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) {
This page took 0.023143 seconds and 4 git commands to generate.