Skip to content

Commit 6d0e6f9

Browse files
committed
[core] Fix memory leak in VectorPool class.
1 parent 68c7380 commit 6d0e6f9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

source/core/support/simplevector.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,20 @@ class VectorPool
629629
mPool.reserve(initialPoolSize);
630630
}
631631

632+
~VectorPool()
633+
{
634+
for (auto&& p : mPool)
635+
{
636+
delete p;
637+
#ifdef POV_CORE_DEBUG
638+
--mAllocCount;
639+
#endif
640+
}
641+
#ifdef POV_CORE_DEBUG
642+
POV_CORE_ASSERT(mAllocCount == 0);
643+
#endif
644+
}
645+
632646
VectorPool(const VectorPool&) = delete;
633647
VectorPool& operator=(VectorPool&) = delete;
634648

@@ -638,6 +652,9 @@ class VectorPool
638652
if (mPool.empty())
639653
{
640654
p = new VECTOR_T();
655+
#ifdef POV_CORE_DEBUG
656+
++mAllocCount;
657+
#endif
641658
}
642659
else
643660
{
@@ -660,6 +677,9 @@ class VectorPool
660677

661678
vector<VECTOR_T*> mPool;
662679
size_t mSizeHint;
680+
#ifdef POV_CORE_DEBUG
681+
size_t mAllocCount;
682+
#endif
663683
};
664684

665685
//******************************************************************************

0 commit comments

Comments
 (0)