Fix heap corruption and memory leak in UniformBuffer move assignment

This commit is contained in:
Mathias Agopian
2026-03-31 11:16:29 -07:00
committed by Mathias Agopian
parent ea3b0aa6f3
commit 3bc67ca00f
+7 -2
View File
@@ -59,14 +59,19 @@ UniformBuffer::UniformBuffer(UniformBuffer&& rhs) noexcept
UniformBuffer& UniformBuffer::operator=(UniformBuffer&& rhs) noexcept {
if (this != &rhs) {
mSomethingDirty = rhs.mSomethingDirty;
if (mBuffer && !isLocalStorage()) {
free(mBuffer, mSize);
}
if (UTILS_LIKELY(rhs.isLocalStorage())) {
mBuffer = mStorage;
mSize = rhs.mSize;
memcpy(mBuffer, rhs.mBuffer, rhs.mSize);
} else {
std::swap(mBuffer, rhs.mBuffer);
std::swap(mSize, rhs.mSize);
mBuffer = rhs.mBuffer;
mSize = rhs.mSize;
}
rhs.mBuffer = nullptr;
rhs.mSize = 0;
}
return *this;
}