Only free the old buffer if we owned it and set owning flag.
* If we cloned the buffer due to misalignment, only free the old buffer if we actually own it (i.e. if it was allocated by us). * Set the KMESSAGE_OWNS_BUFFER flag after cloning the buffer. Previously the buffer was leaked in the clone case.
This commit is contained in:
@@ -836,11 +836,12 @@ KMessage::_InitFromBuffer(bool sizeFromBuffer)
|
|||||||
|
|
||||||
memcpy(buffer, fBuffer, fBufferCapacity);
|
memcpy(buffer, fBuffer, fBufferCapacity);
|
||||||
|
|
||||||
if ((fFlags & KMESSAGE_CLONE_BUFFER) == 0)
|
if ((fFlags & KMESSAGE_OWNS_BUFFER) != 0)
|
||||||
free(fBuffer);
|
free(fBuffer);
|
||||||
|
|
||||||
fBuffer = buffer;
|
fBuffer = buffer;
|
||||||
fFlags &= ~(uint32)(KMESSAGE_READ_ONLY | KMESSAGE_CLONE_BUFFER);
|
fFlags &= ~(uint32)(KMESSAGE_READ_ONLY | KMESSAGE_CLONE_BUFFER);
|
||||||
|
fFlags |= KMESSAGE_OWNS_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_Align(fBuffer) != fBuffer)
|
if (_Align(fBuffer) != fBuffer)
|
||||||
|
|||||||
Reference in New Issue
Block a user