From dc19da18ee37d4780a4f61cf7198b0123e82b2d7 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Sat, 22 Feb 2020 10:54:23 -0800 Subject: [PATCH] fix memory leak due to custom container not handling copy operator for recursive containers --- src/BulletSoftBody/btSoftBody.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index f6812fd10..d14ef82dc 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -105,7 +105,17 @@ static inline btDbvtNode* buildTreeBottomUp(btAlignedObjectArray& l } } leafNodes = newLeafNodes; - adj = newAdj; + //this assignment leaks memory, the assignment doesn't do a deep copy, for now a manual copy + //adj = newAdj; + adj.clear(); + adj.resize(newAdj.size()); + for (int i = 0; i < newAdj.size(); i++) + { + for (int j = 0; j < newAdj[i].size(); j++) + { + adj[i].push_back(newAdj[i][j]); + } + } N = leafNodes.size(); } return leafNodes[0];