libobs/util: Fix pthread mutex leaks

This commit is contained in:
jpark37 2021-08-23 22:04:04 -07:00
parent 0c208f1e62
commit 8a43c55918
2 changed files with 8 additions and 13 deletions

View file

@ -61,16 +61,6 @@ struct config_data {
pthread_mutex_t mutex; pthread_mutex_t mutex;
}; };
static inline bool init_mutex(config_t *config)
{
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr) != 0)
return false;
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
return false;
return pthread_mutex_init(&config->mutex, &attr) == 0;
}
config_t *config_create(const char *file) config_t *config_create(const char *file)
{ {
struct config_data *config; struct config_data *config;
@ -83,7 +73,7 @@ config_t *config_create(const char *file)
config = bzalloc(sizeof(struct config_data)); config = bzalloc(sizeof(struct config_data));
if (!init_mutex(config)) { if (pthread_mutex_init_recursive(&config->mutex) != 0) {
bfree(config); bfree(config);
return NULL; return NULL;
} }
@ -302,7 +292,7 @@ int config_open(config_t **config, const char *file,
if (!*config) if (!*config)
return CONFIG_ERROR; return CONFIG_ERROR;
if (!init_mutex(*config)) { if (pthread_mutex_init_recursive(&(*config)->mutex) != 0) {
bfree(*config); bfree(*config);
return CONFIG_ERROR; return CONFIG_ERROR;
} }
@ -330,7 +320,7 @@ int config_open_string(config_t **config, const char *str)
if (!*config) if (!*config)
return CONFIG_ERROR; return CONFIG_ERROR;
if (!init_mutex(*config)) { if (pthread_mutex_init_recursive(&(*config)->mutex) != 0) {
bfree(*config); bfree(*config);
return CONFIG_ERROR; return CONFIG_ERROR;
} }

View file

@ -825,6 +825,8 @@ void profiler_free(void)
} }
da_free(old_root_entries); da_free(old_root_entries);
pthread_mutex_destroy(&root_mutex);
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -858,6 +860,9 @@ void profiler_name_store_free(profiler_name_store_t *store)
bfree(store->names.array[i]); bfree(store->names.array[i]);
da_free(store->names); da_free(store->names);
pthread_mutex_destroy(&store->mutex);
bfree(store); bfree(store);
} }