diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2016-08-26 15:25:03 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2016-08-26 15:28:50 +0300 |
commit | 62b1cdd66e39db58e422e15b20a80d5e05f3dd4f (patch) | |
tree | c80b6eefbc2d638d2b049acbe3e60cbbf3c3f67a /source/blender/blenkernel/intern/cachefile.c | |
parent | 8870c454a1aa9cd8a0547d533fc0d7fc2a048ca0 (diff) |
Fix over creation of cache files handles (leading to memory leaks).
Multiple threads could create multiple handles for the same cache file,
so protect handle creation with a mutex, to make sure only one is
created.
Diffstat (limited to 'source/blender/blenkernel/intern/cachefile.c')
-rw-r--r-- | source/blender/blenkernel/intern/cachefile.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 16f263791db..502f1d53ab2 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -35,6 +35,7 @@ #include "BLI_listbase.h" #include "BLI_path_util.h" #include "BLI_string.h" +#include "BLI_threads.h" #include "BLI_utildefines.h" #include "BKE_animsys.h" @@ -48,6 +49,13 @@ # include "ABC_alembic.h" #endif +static SpinLock spin; + +void BKE_cachefiles_init(void) +{ + BLI_spin_init(&spin); +} + void *BKE_cachefile_add(Main *bmain, const char *name) { CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name); @@ -65,6 +73,7 @@ void BKE_cachefile_init(CacheFile *cache_file) cache_file->frame = 0.0f; cache_file->is_sequence = false; cache_file->scale = 1.0f; + cache_file->handle_mutex = BLI_mutex_alloc(); } /** Free (or release) any data used by this cachefile (does not free the cachefile itself). */ @@ -76,6 +85,7 @@ void BKE_cachefile_free(CacheFile *cache_file) ABC_free_handle(cache_file->handle); #endif + BLI_mutex_free(cache_file->handle_mutex); BLI_freelistN(&cache_file->object_paths); } @@ -114,9 +124,19 @@ void BKE_cachefile_reload(const Main *bmain, CacheFile *cache_file) void BKE_cachefile_ensure_handle(const Main *bmain, CacheFile *cache_file) { + BLI_spin_lock(&spin); + if (cache_file->handle_mutex == NULL) { + cache_file->handle_mutex = BLI_mutex_alloc(); + } + BLI_spin_unlock(&spin); + + BLI_mutex_lock(cache_file->handle_mutex); + if (cache_file->handle == NULL) { BKE_cachefile_reload(bmain, cache_file); } + + BLI_mutex_unlock(cache_file->handle_mutex); } void BKE_cachefile_update_frame(Main *bmain, Scene *scene, const float ctime, const float fps) |