From 945c77d699c0911fabff1e1264e86010b91d0707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mar=C4=8Dinkovi=C4=87?= Date: Thu, 9 Feb 2023 12:23:43 +0100 Subject: [PATCH] Fix double free when the mesh contains duplicate bones. --- include/assimp/mesh.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/assimp/mesh.h b/include/assimp/mesh.h index 3ef94e606..45f50d5a5 100644 --- a/include/assimp/mesh.h +++ b/include/assimp/mesh.h @@ -59,6 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #ifdef __cplusplus +#include + extern "C" { #endif @@ -872,11 +874,15 @@ struct aiMesh { // DO NOT REMOVE THIS ADDITIONAL CHECK if (mNumBones && mBones) { + std::unordered_set bones; for (unsigned int a = 0; a < mNumBones; a++) { if (mBones[a]) { - delete mBones[a]; + bones.insert(mBones[a]); } } + for (const aiBone *bone: bones) { + delete bone; + } delete[] mBones; }