From 12f184867e514e393c9e4eaa78d8cf421759476e Mon Sep 17 00:00:00 2001 From: Mike Samsonov Date: Tue, 19 Nov 2019 17:05:24 +0000 Subject: [PATCH] Fix for memory leak in glTF2 Importer if an exception has been thrown --- code/glTF2/glTF2Asset.inl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/glTF2/glTF2Asset.inl b/code/glTF2/glTF2Asset.inl index 6b47b1607..0d4de11f2 100644 --- a/code/glTF2/glTF2Asset.inl +++ b/code/glTF2/glTF2Asset.inl @@ -270,13 +270,14 @@ Ref LazyDict::Retrieve(unsigned int i) throw DeadlyImportError("GLTF: Object at index \"" + to_string(i) + "\" is not a JSON object"); } - T* inst = new T(); + // Unique ptr prevents memory leak in case of Read throws an exception + auto inst = std::unique_ptr(); inst->id = std::string(mDictId) + "_" + to_string(i); inst->oIndex = i; ReadMember(obj, "name", inst->name); inst->Read(obj, mAsset); - return Add(inst); + return Add(inst.release()); } template