Fix resource leak in error cases. CID 611238.

This commit is contained in:
Rene Gollent 2012-07-14 11:24:22 -04:00
parent 2a8e9bb83d
commit c163f973e6

View File

@ -281,6 +281,9 @@ BMessageValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
uint8* messageBuffer = new(std::nothrow) uint8[totalSize]; uint8* messageBuffer = new(std::nothrow) uint8[totalSize];
if (messageBuffer == NULL) if (messageBuffer == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
ArrayDeleter<uint8> deleter(messageBuffer);
memset(messageBuffer, 0, totalSize); memset(messageBuffer, 0, totalSize);
memcpy(messageBuffer, fHeader, sizeof(BMessage::message_header)); memcpy(messageBuffer, fHeader, sizeof(BMessage::message_header));
uint8* tempBuffer = messageBuffer + sizeof(BMessage::message_header); uint8* tempBuffer = messageBuffer + sizeof(BMessage::message_header);
@ -313,7 +316,6 @@ BMessageValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader,
} }
error = fMessage.Unflatten((const char*)messageBuffer); error = fMessage.Unflatten((const char*)messageBuffer);
delete[] messageBuffer;
if (error != B_OK) if (error != B_OK)
return error; return error;