[ip6] fix message leak when using platform TCP (#6679)

When using platform TCP, `Ip6::HandlePayload()` will be called with
`aIpProto = kProtoTcp` and `aMessageOwnerShip =
kTakeCustody`. `FreeMessage()` will be called with `message =
nullptr`, causing the message to leak. This commit fixes this issue.
This commit is contained in:
Jiacheng Guo
2021-05-26 14:51:05 -07:00
committed by GitHub
parent 907c9bdcaf
commit d346481494
+2 -8
View File
@@ -946,19 +946,13 @@ Error Ip6::HandlePayload(Message & aMessage,
Message::Ownership aMessageOwnership)
{
Error error = kErrorNone;
Message *message = nullptr;
Message *message = (aMessageOwnership == Message::kTakeCustody) ? &aMessage : nullptr;
VerifyOrExit(aIpProto == kProtoUdp || aIpProto == kProtoIcmp6);
switch (aMessageOwnership)
if (aMessageOwnership == Message::kCopyToUse)
{
case Message::kTakeCustody:
message = &aMessage;
break;
case Message::kCopyToUse:
VerifyOrExit((message = aMessage.Clone()) != nullptr, error = kErrorNoBufs);
break;
}
switch (aIpProto)