From 9a87646122bb87e350f8c1886d47db0d466c0868 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 10 Dec 2011 18:46:29 +0100 Subject: [PATCH] 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. --- src/system/kernel/messaging/KMessage.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/messaging/KMessage.cpp b/src/system/kernel/messaging/KMessage.cpp index e6b5800932..d4dbf03c7d 100644 --- a/src/system/kernel/messaging/KMessage.cpp +++ b/src/system/kernel/messaging/KMessage.cpp @@ -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)