add pw_deinit() to cleanup resources

Add and use pw_deinit() to avoid leaking the support plugins and
use this in the main daemon. Makes valgrind output better.
This commit is contained in:
Wim Taymans 2020-06-02 17:16:46 +02:00
parent 09913ca4ab
commit 00d61d958e
3 changed files with 27 additions and 0 deletions

View file

@ -132,6 +132,7 @@ int main(int argc, char *argv[])
pw_daemon_config_free(config); pw_daemon_config_free(config);
pw_context_destroy(context); pw_context_destroy(context);
pw_main_loop_destroy(loop); pw_main_loop_destroy(loop);
pw_deinit();
return 0; return 0;
} }

View file

@ -409,6 +409,30 @@ void pw_init(int *argc, char **argv[])
pw_log_info("version %s", pw_get_library_version()); pw_log_info("version %s", pw_get_library_version());
} }
SPA_EXPORT
void pw_deinit(void)
{
struct support *support = &global_support;
struct registry *registry = &global_registry;
struct plugin *p;
support->plugin_dir = NULL;
if (support->categories)
pw_free_strv(support->categories);
support->categories = NULL;
support->support_lib = NULL;
pw_log_set(NULL);
spa_list_consume(p, &registry->plugins, link) {
struct handle *h;
p->ref++;
spa_list_consume(h, &p->handles, link)
unref_handle(h);
unref_plugin(p);
}
}
/** Check if a debug category is enabled /** Check if a debug category is enabled
* *
* \param name the name of the category to check * \param name the name of the category to check

View file

@ -116,6 +116,8 @@ extern "C" {
void void
pw_init(int *argc, char **argv[]); pw_init(int *argc, char **argv[]);
void pw_deinit(void);
bool bool
pw_debug_is_category_enabled(const char *name); pw_debug_is_category_enabled(const char *name);