mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-25 11:28:38 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user