1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

libdm: Fix a data race in dm_pool_{create,destroy}.

This commit is contained in:
Petr Rockai 2013-10-09 22:19:06 +02:00
parent 529a13ec89
commit b5aad86710
2 changed files with 11 additions and 2 deletions

View File

@ -62,7 +62,9 @@ struct dm_pool *dm_pool_create(const char *name, size_t chunk_hint)
while (new_size < p->chunk_size) while (new_size < p->chunk_size)
new_size <<= 1; new_size <<= 1;
p->chunk_size = new_size; p->chunk_size = new_size;
pthread_mutex_lock(&_dm_pools_mutex);
dm_list_add(&_dm_pools, &p->list); dm_list_add(&_dm_pools, &p->list);
pthread_mutex_unlock(&_dm_pools_mutex);
return p; return p;
} }
@ -77,7 +79,9 @@ void dm_pool_destroy(struct dm_pool *p)
c = pr; c = pr;
} }
pthread_mutex_lock(&_dm_pools_mutex);
dm_list_del(&p->list); dm_list_del(&p->list);
pthread_mutex_unlock(&_dm_pools_mutex);
dm_free(p); dm_free(p);
} }

View File

@ -15,9 +15,10 @@
#include "dmlib.h" #include "dmlib.h"
#include <sys/mman.h> #include <sys/mman.h>
#include <pthread.h>
/* FIXME: thread unsafe */
static DM_LIST_INIT(_dm_pools); static DM_LIST_INIT(_dm_pools);
static pthread_mutex_t _dm_pools_mutex = PTHREAD_MUTEX_INITIALIZER;
void dm_pools_check_leaks(void); void dm_pools_check_leaks(void);
#ifdef DEBUG_ENFORCE_POOL_LOCKING #ifdef DEBUG_ENFORCE_POOL_LOCKING
@ -81,8 +82,11 @@ void dm_pools_check_leaks(void)
{ {
struct dm_pool *p; struct dm_pool *p;
if (dm_list_empty(&_dm_pools)) pthread_mutex_lock(&_dm_pools_mutex);
if (dm_list_empty(&_dm_pools)) {
pthread_mutex_unlock(&_dm_pools_mutex);
return; return;
}
log_error("You have a memory leak (not released memory pool):"); log_error("You have a memory leak (not released memory pool):");
dm_list_iterate_items(p, &_dm_pools) { dm_list_iterate_items(p, &_dm_pools) {
@ -94,6 +98,7 @@ void dm_pools_check_leaks(void)
log_error(" [%p] %s", p, p->name); log_error(" [%p] %s", p, p->name);
#endif #endif
} }
pthread_mutex_unlock(&_dm_pools_mutex);
log_error(INTERNAL_ERROR "Unreleased memory pool(s) found."); log_error(INTERNAL_ERROR "Unreleased memory pool(s) found.");
} }