diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-16 11:00:10 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 627bd655347cb3aaf04b352e4f0a0207d64c8cb1 (patch) | |
tree | b45b2a341b1e5675f8af3662e5a124fcf6093d4e /include/odhtdb/OwnedMemory.hpp | |
parent | 97c9ff702f002925dcd33869d0e22eda18390e2e (diff) |
Fix memory leak (mismatch free/delete/delete[]), fix invalid memory access
Diffstat (limited to 'include/odhtdb/OwnedMemory.hpp')
-rw-r--r-- | include/odhtdb/OwnedMemory.hpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/odhtdb/OwnedMemory.hpp b/include/odhtdb/OwnedMemory.hpp index 67afe06..4c6df1c 100644 --- a/include/odhtdb/OwnedMemory.hpp +++ b/include/odhtdb/OwnedMemory.hpp @@ -22,4 +22,32 @@ namespace odhtdb void *data; usize size; }; + + class OwnedByteArray + { + public: + OwnedByteArray() : data(nullptr), size(0) {} + OwnedByteArray(u8 *_data, usize _size) : data(_data), size(_size) {} + OwnedByteArray(OwnedByteArray &&other) + { + data = other.data; + size = other.size; + + other.data = nullptr; + other.size = 0; + } + ~OwnedByteArray() + { + delete[] data; + } + + // Do not allow copy of this struct, forcing move when returning a OwnedByteArray in a function + OwnedByteArray(OwnedByteArray&) = delete; + OwnedByteArray& operator = (OwnedByteArray&) = delete; + + const DataView getView() const { return DataView(data, size); } + + u8 *data; + usize size; + }; } |