Fix for memory leak in glTF2 Importer if an exception has been thrown

pull/2770/head
Mike Samsonov 2019-11-19 17:05:24 +00:00
parent a9f82dbe0b
commit 12f184867e
1 changed files with 3 additions and 2 deletions

View File

@ -270,13 +270,14 @@ Ref<T> LazyDict<T>::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<T>();
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<class T>