Fix memory leak on cpp object api (#5761)

Previously UnPack would allocate data with new and assign it to a
raw pointer. This behavior makes it possible for the pointer to be
leaked in case of OOM. This commit defaults to use the user specified
pointer (which needs to implement a move constructor, a .get() and a
 .release() operators), thus preventing these leaks.
This commit is contained in:
xtrm0
2020-02-12 20:12:45 +00:00
committed by GitHub
parent 17557f9131
commit 54f8b787cb
11 changed files with 87 additions and 81 deletions

View File

@@ -262,9 +262,9 @@ inline flatbuffers::Offset<MonsterExtra> CreateMonsterExtraDirect(
flatbuffers::Offset<MonsterExtra> CreateMonsterExtra(flatbuffers::FlatBufferBuilder &_fbb, const MonsterExtraT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
inline MonsterExtraT *MonsterExtra::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = new MonsterExtraT();
UnPackTo(_o, _resolver);
return _o;
flatbuffers::unique_ptr<MyGame::MonsterExtraT> _o = flatbuffers::unique_ptr<MyGame::MonsterExtraT>(new MonsterExtraT());
UnPackTo(_o.get(), _resolver);
return _o.release();
}
inline void MonsterExtra::UnPackTo(MonsterExtraT *_o, const flatbuffers::resolver_function_t *_resolver) const {