otAddUnicastAddress Doesn't Hold onto External Pointers (#504)

* Modify ot*UnicastAddress functions to use internal memory instead of holding onto an external memory address.
This commit is contained in:
Nick Banks
2016-09-02 16:17:08 -07:00
committed by Jonathan Hui
parent 73060ae8e1
commit 511ade5293
9 changed files with 190 additions and 107 deletions
+8 -10
View File
@@ -102,8 +102,6 @@ const struct Command Interpreter::sCommands[] =
#endif
};
otNetifAddress Interpreter::sAddress;
static otDEFINE_ALIGNED_VAR(sPingTimerBuf, sizeof(Timer), uint64_t);
Timer *Interpreter::sPingTimer;
@@ -611,14 +609,15 @@ exit:
ThreadError Interpreter::ProcessIpAddrAdd(int argc, char *argv[])
{
ThreadError error;
otNetifAddress aAddress;
VerifyOrExit(argc > 0, error = kThreadError_Parse);
SuccessOrExit(error = otIp6AddressFromString(argv[0], &sAddress.mAddress));
sAddress.mPrefixLength = 64;
sAddress.mPreferredLifetime = 0xffffffff;
sAddress.mValidLifetime = 0xffffffff;
error = otAddUnicastAddress(&sAddress);
SuccessOrExit(error = otIp6AddressFromString(argv[0], &aAddress.mAddress));
aAddress.mPrefixLength = 64;
aAddress.mPreferredLifetime = 0xffffffff;
aAddress.mValidLifetime = 0xffffffff;
error = otAddUnicastAddress(&aAddress);
exit:
return error;
@@ -632,8 +631,7 @@ ThreadError Interpreter::ProcessIpAddrDel(int argc, char *argv[])
VerifyOrExit(argc > 0, error = kThreadError_Parse);
SuccessOrExit(error = otIp6AddressFromString(argv[0], &address));
VerifyOrExit(otIsIp6AddressEqual(&address, &sAddress.mAddress), error = kThreadError_Parse);
error = otRemoveUnicastAddress(&sAddress);
error = otRemoveUnicastAddress(&address);
exit:
return error;
@@ -1989,7 +1987,7 @@ void Interpreter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
if (!found)
{
otRemoveUnicastAddress(address);
otRemoveUnicastAddress(&address->mAddress);
address->mValidLifetime = 0;
}
}