From 0471ba7fbadc85335a80f8cd8f5a571714158ab5 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 2 Jun 2020 17:38:07 +0200 Subject: [PATCH] Add pw_in_valgrind() to check running in valgrind In valgrind we don't want to unload the plugins because then valgrind doesn't know the symbol names where things leaked. Parse the VALGRIND env variable and use this to avoid calling dlclose for a better valgrind experience. --- src/pipewire/impl-module.c | 2 +- src/pipewire/pipewire.c | 13 ++++++++++++- src/pipewire/pipewire.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pipewire/impl-module.c b/src/pipewire/impl-module.c index 8f12d2ea8..123d331ed 100644 --- a/src/pipewire/impl-module.c +++ b/src/pipewire/impl-module.c @@ -322,7 +322,7 @@ void pw_impl_module_destroy(struct pw_impl_module *module) pw_properties_free(module->properties); - if (dlclose(impl->hnd) != 0) + if (!pw_in_valgrind() && dlclose(impl->hnd) != 0) pw_log_warn(NAME" %p: dlclose failed: %s", module, dlerror()); free(impl); } diff --git a/src/pipewire/pipewire.c b/src/pipewire/pipewire.c index e313b32a2..ff156172c 100644 --- a/src/pipewire/pipewire.c +++ b/src/pipewire/pipewire.c @@ -74,6 +74,7 @@ struct support { struct registry *registry; struct spa_support support[MAX_SUPPORT]; uint32_t n_support; + unsigned int in_valgrind:1; }; static struct registry global_registry; @@ -154,7 +155,8 @@ unref_plugin(struct plugin *plugin) if (--plugin->ref == 0) { spa_list_remove(&plugin->link); pw_log_debug("unloaded plugin:'%s'", plugin->filename); - dlclose(plugin->hnd); + if (!global_support.in_valgrind) + dlclose(plugin->hnd); free(plugin->filename); free(plugin); } @@ -367,6 +369,9 @@ void pw_init(int *argc, char **argv[]) if (support->registry != NULL) return; + if ((str = getenv("VALGRIND"))) + support->in_valgrind = pw_properties_parse_bool(str); + if ((str = getenv("PIPEWIRE_DEBUG"))) configure_debug(support, str); @@ -506,6 +511,12 @@ const char *pw_get_host_name(void) return hname; } +SPA_EXPORT +bool pw_in_valgrind(void) +{ + return global_support.in_valgrind; +} + /** Get the client name * * Make a new PipeWire client name that can be used to construct a remote. diff --git a/src/pipewire/pipewire.h b/src/pipewire/pipewire.h index 4fa01dd4e..d73194a6d 100644 --- a/src/pipewire/pipewire.h +++ b/src/pipewire/pipewire.h @@ -136,6 +136,8 @@ pw_get_host_name(void); const char * pw_get_client_name(void); +bool pw_in_valgrind(void); + enum pw_direction pw_direction_reverse(enum pw_direction direction);