[Bf-blender-cvs] [1b1292b7b1c] functions: assert that the number of temporary buffers does not grow unbounded

Jacques Lucke noreply at git.blender.org
Wed Sep 4 19:43:22 CEST 2019


Commit: 1b1292b7b1c68ee851d6dfdd7440daac072f1882
Author: Jacques Lucke
Date:   Wed Sep 4 12:48:27 2019 +0200
Branches: functions
https://developer.blender.org/rB1b1292b7b1c68ee851d6dfdd7440daac072f1882

assert that the number of temporary buffers does not grow unbounded

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

M	source/blender/blenlib/intern/BLI_temporary_allocator.cpp

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

diff --git a/source/blender/blenlib/intern/BLI_temporary_allocator.cpp b/source/blender/blenlib/intern/BLI_temporary_allocator.cpp
index 87c415663ff..9dd2404f39b 100644
--- a/source/blender/blenlib/intern/BLI_temporary_allocator.cpp
+++ b/source/blender/blenlib/intern/BLI_temporary_allocator.cpp
@@ -62,6 +62,7 @@ static void raw_deallocate(void *ptr)
 }
 
 struct ThreadLocalBuffers {
+  uint allocated_amount = 0;
   Stack<void *, 32, RawAllocator> buffers;
 
   ~ThreadLocalBuffers()
@@ -76,12 +77,17 @@ thread_local ThreadLocalBuffers local_storage;
 
 void *BLI_temporary_allocate(uint size)
 {
+  /* The total amount of allocated buffers using this allocator should be limited by a constant. If
+   * it grows unbounded, there is likely a memory leak somewhere. */
+  BLI_assert(local_storage.allocated_amount < 100);
+
   if (size <= SMALL_BUFFER_SIZE) {
     auto &buffers = local_storage.buffers;
     if (buffers.empty()) {
       void *ptr = raw_allocate(SMALL_BUFFER_SIZE);
       MemHead &memhead = get_memhead(ptr);
       memhead.type = TemporaryBufferType::Small;
+      local_storage.allocated_amount++;
       return ptr;
     }
     else {



More information about the Bf-blender-cvs mailing list