[mle] properly free message on error in InformPreviousParent() (#2187)

`InformPreviousParent()` uses `Ip6::SendDatagram()` to submit an IPv6
datagram with no next header.  However, if `Ip6::SendDatagram()` returns
an error, custody of the message buffer remains with the caller.  This
commit ensures the message buffer is properly freed in this case.
This commit is contained in:
Jonathan Hui
2017-09-13 14:08:09 -07:00
committed by GitHub
parent 8cade88f29
commit 782328a6c2
+5 -6
View File
@@ -3298,20 +3298,19 @@ otError Mle::InformPreviousParent(void)
messageInfo.SetInterfaceId(netif.GetInterfaceId());
SuccessOrExit(error = netif.GetIp6().SendDatagram(*message, messageInfo, Ip6::kProtoNone));
message = NULL;
otLogInfoMle(GetInstance(), "Sending message to inform previous parent 0x%04x", mPreviousParentRloc);
exit:
if (message != NULL)
{
message->Free();
}
if (error != OT_ERROR_NONE)
{
otLogWarnMle(GetInstance(), "Failed to inform previous parent, error:%s", otThreadErrorToString(error));
if (message != NULL)
{
message->Free();
}
}
return error;