summaryrefslogtreecommitdiff
path: root/source/core/slang-blob.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-11-20 17:24:35 -0500
committerGitHub <noreply@github.com>2020-11-20 17:24:35 -0500
commitc0fab438a565cb2134679af8830d11644668d6a2 (patch)
tree3eeccfd634c2853467f42abe51a0d7008dbb93a2 /source/core/slang-blob.h
parentee5842a01cdb2bd6cd4acee7214666f180b95d84 (diff)
Bug fixes: Memory leak/off by one on UIntSet (#1616)
* #include an absolute path didn't work - because paths were taken to always be relative. * Fix memory leak on ScopedAllocation. Fix off by one bug on UIntSet
Diffstat (limited to 'source/core/slang-blob.h')
-rw-r--r--source/core/slang-blob.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h
index 8bf02512d..d326f9c9c 100644
--- a/source/core/slang-blob.h
+++ b/source/core/slang-blob.h
@@ -109,17 +109,41 @@ public:
m_sizeInBytes = size;
}
+ void* set(const void* data, size_t size)
+ {
+ void* dst = allocate(size);
+ if (dst)
+ {
+ memcpy(dst, data, size);
+ }
+ return dst;
+ }
+
/// Get the allocated data. Returns nullptr if there is no allocated data
void* getData() const { return m_data; }
/// Get the size of the allocated data.
size_t getSizeInBytes() const { return m_sizeInBytes; }
+ void swap(ThisType& rhs)
+ {
+ void*const data = m_data;
+ const size_t sizeInBytes = m_sizeInBytes;
+
+ m_data = rhs.m_data;
+ m_sizeInBytes = rhs.m_sizeInBytes;
+
+ rhs.m_data = data;
+ rhs.m_sizeInBytes = sizeInBytes;
+ }
+
ScopedAllocation() :
m_data(nullptr),
m_sizeInBytes(0)
{
}
+ ~ScopedAllocation() { deallocate(); }
+
private:
// disable
ScopedAllocation(const ThisType& rhs) = delete;
@@ -153,6 +177,12 @@ public:
blob->m_data.attach(data, dataCount);
return blob;
}
+ static RefPtr<RawBlob> moveCreate(ScopedAllocation& alloc)
+ {
+ RawBlob* blob = new RawBlob;
+ blob->m_data.swap(alloc);
+ return blob;
+ }
protected:
RawBlob() = default;