[Bf-blender-cvs] [1cd6c7f] openvdb: Cycles: fix memory leaks due to hash collision.

Kévin Dietrich noreply at git.blender.org
Mon Jan 25 16:15:33 CET 2016


Commit: 1cd6c7fcd4664b451f79ccea7f8e46d5070702ef
Author: Kévin Dietrich
Date:   Mon Jan 25 12:43:35 2016 +0100
Branches: openvdb
https://developer.blender.org/rB1cd6c7fcd4664b451f79ccea7f8e46d5070702ef

Cycles: fix memory leaks due to hash collision.

Also clean the code a bit.

===================================================================

M	intern/cycles/util/util_volume.cpp

===================================================================

diff --git a/intern/cycles/util/util_volume.cpp b/intern/cycles/util/util_volume.cpp
index b5fca18..b7a4535 100644
--- a/intern/cycles/util/util_volume.cpp
+++ b/intern/cycles/util/util_volume.cpp
@@ -33,18 +33,18 @@ void create_isectors_threads(unordered_map<pthread_t, IsectorType *> &isect_map,
                              const vector<pthread_t> &thread_ids,
                              const IsectorType &main_isect)
 {
+	release_map_memory(isect_map);
+
 	pthread_t my_thread = pthread_self();
 
 	for (size_t i = 0; i < thread_ids.size(); ++i) {
-		IsectorType *isect = new IsectorType(main_isect);
-		pair<pthread_t, IsectorType *> inter(thread_ids[i], isect);
-		isect_map.insert(inter);
+		if (isect_map.find(thread_ids[i]) == isect_map.end()) {
+			isect_map[thread_ids[i]] = new IsectorType(main_isect);
+		}
 	}
 
 	if (isect_map.find(my_thread) == isect_map.end()) {
-		IsectorType *isect = new IsectorType(main_isect);
-		pair<pthread_t, IsectorType *> inter(my_thread, isect);
-		isect_map.insert(inter);
+		isect_map[my_thread] = new IsectorType(main_isect);
 	}
 }
 
@@ -55,22 +55,23 @@ void create_samplers_threads(unordered_map<pthread_t, SamplerType *> &sampler_ma
                              const openvdb::math::Transform *transform,
                              const AccessorType &main_accessor)
 {
+	release_map_memory(sampler_map);
+
 	pthread_t my_thread = pthread_self();
 
 	for (size_t i = 0; i < thread_ids.size(); ++i) {
 		AccessorType *accessor = new AccessorType(main_accessor);
 		accessors.push_back(accessor);
-		SamplerType *sampler = new SamplerType(*accessor, *transform);
-		pair<pthread_t, SamplerType *> sampl(thread_ids[i], sampler);
-		sampler_map.insert(sampl);
+
+		if (sampler_map.find(thread_ids[i]) == sampler_map.end()) {
+			sampler_map[thread_ids[i]] = new SamplerType(*accessor, *transform);
+		}
 	}
 
 	if (sampler_map.find(my_thread) == sampler_map.end()) {
 		AccessorType *accessor = new AccessorType(main_accessor);
 		accessors.push_back(accessor);
-		SamplerType *sampler = new SamplerType(*accessor, *transform);
-		pair<pthread_t, SamplerType *> sampl(my_thread, sampler);
-		sampler_map.insert(sampl);
+		sampler_map[my_thread] = new SamplerType(*accessor, *transform);
 	}
 }




More information about the Bf-blender-cvs mailing list