]> sourceware.org Git - lvm2.git/commitdiff
libdm: Fix a data race in dm_pool_{create,destroy}.
authorPetr Rockai <prockai@redhat.com>
Wed, 9 Oct 2013 20:19:06 +0000 (22:19 +0200)
committerPetr Rockai <prockai@redhat.com>
Wed, 9 Oct 2013 22:34:35 +0000 (00:34 +0200)
libdm/mm/pool-fast.c
libdm/mm/pool.c

index 2b494d629f6b90a9051ca471a2a68f101d60bdb4..edb31a07c828e4c60fd94847706433f902406e4d 100644 (file)
@@ -62,7 +62,9 @@ struct dm_pool *dm_pool_create(const char *name, size_t chunk_hint)
        while (new_size < p->chunk_size)
                new_size <<= 1;
        p->chunk_size = new_size;
+       pthread_mutex_lock(&_dm_pools_mutex);
        dm_list_add(&_dm_pools, &p->list);
+       pthread_mutex_unlock(&_dm_pools_mutex);
        return p;
 }
 
@@ -77,7 +79,9 @@ void dm_pool_destroy(struct dm_pool *p)
                c = pr;
        }
 
+       pthread_mutex_lock(&_dm_pools_mutex);
        dm_list_del(&p->list);
+       pthread_mutex_unlock(&_dm_pools_mutex);
        dm_free(p);
 }
 
index fd08307f62972b089ea401b535d624a39c76c2ab..ef006a444527ed91366addd44afd6154de9e9264 100644 (file)
 
 #include "dmlib.h"
 #include <sys/mman.h>
+#include <pthread.h>
 
-/* FIXME: thread unsafe */
 static DM_LIST_INIT(_dm_pools);
+static pthread_mutex_t _dm_pools_mutex = PTHREAD_MUTEX_INITIALIZER;
 void dm_pools_check_leaks(void);
 
 #ifdef DEBUG_ENFORCE_POOL_LOCKING
@@ -81,8 +82,11 @@ void dm_pools_check_leaks(void)
 {
        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;
+       }
 
        log_error("You have a memory leak (not released memory pool):");
        dm_list_iterate_items(p, &_dm_pools) {
@@ -94,6 +98,7 @@ void dm_pools_check_leaks(void)
                log_error(" [%p] %s", p, p->name);
 #endif
        }
+       pthread_mutex_unlock(&_dm_pools_mutex);
        log_error(INTERNAL_ERROR "Unreleased memory pool(s) found.");
 }
 
This page took 0.039549 seconds and 5 git commands to generate.