diff options
author | xtrm0 <afonso.tfaria21@gmail.com> | 2020-02-12 20:12:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-12 12:12:45 -0800 |
commit | 54f8b787cbdac587b1c9fec1ffe5a2ad2f0d61a2 (patch) | |
tree | f58c6bec9f1956bb08e37a591d0befc12ae2eb2c /tests/namespace_test | |
parent | 17557f913108649f98d374c6a55f2010922ca6c2 (diff) | |
download | flatbuffers-54f8b787cbdac587b1c9fec1ffe5a2ad2f0d61a2.tar.gz flatbuffers-54f8b787cbdac587b1c9fec1ffe5a2ad2f0d61a2.tar.bz2 flatbuffers-54f8b787cbdac587b1c9fec1ffe5a2ad2f0d61a2.zip |
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.
Diffstat (limited to 'tests/namespace_test')
-rw-r--r-- | tests/namespace_test/namespace_test1_generated.h | 6 | ||||
-rw-r--r-- | tests/namespace_test/namespace_test2_generated.h | 18 |
2 files changed, 12 insertions, 12 deletions
diff --git a/tests/namespace_test/namespace_test1_generated.h b/tests/namespace_test/namespace_test1_generated.h index 397e9d13..feae671a 100644 --- a/tests/namespace_test/namespace_test1_generated.h +++ b/tests/namespace_test/namespace_test1_generated.h @@ -172,9 +172,9 @@ inline flatbuffers::Offset<TableInNestedNS> CreateTableInNestedNS( flatbuffers::Offset<TableInNestedNS> CreateTableInNestedNS(flatbuffers::FlatBufferBuilder &_fbb, const TableInNestedNST *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); inline TableInNestedNST *TableInNestedNS::UnPack(const flatbuffers::resolver_function_t *_resolver) const { - auto _o = new TableInNestedNST(); - UnPackTo(_o, _resolver); - return _o; + flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST> _o = flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST>(new TableInNestedNST()); + UnPackTo(_o.get(), _resolver); + return _o.release(); } inline void TableInNestedNS::UnPackTo(TableInNestedNST *_o, const flatbuffers::resolver_function_t *_resolver) const { diff --git a/tests/namespace_test/namespace_test2_generated.h b/tests/namespace_test/namespace_test2_generated.h index 2d9e5cf5..bb6844b8 100644 --- a/tests/namespace_test/namespace_test2_generated.h +++ b/tests/namespace_test/namespace_test2_generated.h @@ -329,9 +329,9 @@ inline flatbuffers::Offset<SecondTableInA> CreateSecondTableInA( flatbuffers::Offset<SecondTableInA> CreateSecondTableInA(flatbuffers::FlatBufferBuilder &_fbb, const SecondTableInAT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); inline TableInFirstNST *TableInFirstNS::UnPack(const flatbuffers::resolver_function_t *_resolver) const { - auto _o = new TableInFirstNST(); - UnPackTo(_o, _resolver); - return _o; + flatbuffers::unique_ptr<NamespaceA::TableInFirstNST> _o = flatbuffers::unique_ptr<NamespaceA::TableInFirstNST>(new TableInFirstNST()); + UnPackTo(_o.get(), _resolver); + return _o.release(); } inline void TableInFirstNS::UnPackTo(TableInFirstNST *_o, const flatbuffers::resolver_function_t *_resolver) const { @@ -365,9 +365,9 @@ inline flatbuffers::Offset<TableInFirstNS> CreateTableInFirstNS(flatbuffers::Fla namespace NamespaceC { inline TableInCT *TableInC::UnPack(const flatbuffers::resolver_function_t *_resolver) const { - auto _o = new TableInCT(); - UnPackTo(_o, _resolver); - return _o; + flatbuffers::unique_ptr<NamespaceC::TableInCT> _o = flatbuffers::unique_ptr<NamespaceC::TableInCT>(new TableInCT()); + UnPackTo(_o.get(), _resolver); + return _o.release(); } inline void TableInC::UnPackTo(TableInCT *_o, const flatbuffers::resolver_function_t *_resolver) const { @@ -398,9 +398,9 @@ inline flatbuffers::Offset<TableInC> CreateTableInC(flatbuffers::FlatBufferBuild namespace NamespaceA { inline SecondTableInAT *SecondTableInA::UnPack(const flatbuffers::resolver_function_t *_resolver) const { - auto _o = new SecondTableInAT(); - UnPackTo(_o, _resolver); - return _o; + flatbuffers::unique_ptr<NamespaceA::SecondTableInAT> _o = flatbuffers::unique_ptr<NamespaceA::SecondTableInAT>(new SecondTableInAT()); + UnPackTo(_o.get(), _resolver); + return _o.release(); } inline void SecondTableInA::UnPackTo(SecondTableInAT *_o, const flatbuffers::resolver_function_t *_resolver) const { |