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:
Michael Lotz 2011-12-10 18:46:29 +01:00
parent d0aa07489c
commit 9a87646122

View File

@ -836,11 +836,12 @@ KMessage::_InitFromBuffer(bool sizeFromBuffer)
memcpy(buffer, fBuffer, fBufferCapacity);
if ((fFlags & KMESSAGE_CLONE_BUFFER) == 0)
if ((fFlags & KMESSAGE_OWNS_BUFFER) != 0)
free(fBuffer);
fBuffer = buffer;
fFlags &= ~(uint32)(KMESSAGE_READ_ONLY | KMESSAGE_CLONE_BUFFER);
fFlags |= KMESSAGE_OWNS_BUFFER;
}
if (_Align(fBuffer) != fBuffer)