Merge pull request #2770 from muxanickms/fix_memory_leak_in_gltf2_on_exception
Fix for memory leak in glTF2 Importer if an exception has been thrownpull/2769/head^2
commit
a98a8edb71
|
@ -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");
|
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>(new T());
|
||||||
inst->id = std::string(mDictId) + "_" + to_string(i);
|
inst->id = std::string(mDictId) + "_" + to_string(i);
|
||||||
inst->oIndex = i;
|
inst->oIndex = i;
|
||||||
ReadMember(obj, "name", inst->name);
|
ReadMember(obj, "name", inst->name);
|
||||||
inst->Read(obj, mAsset);
|
inst->Read(obj, mAsset);
|
||||||
|
|
||||||
return Add(inst);
|
return Add(inst.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
Loading…
Reference in New Issue