mirror of https://github.com/axmolengine/axmol.git
fastSet makes the Data object managing a new memory area in [bytes, bytes + size), but it doesn't releasing the old data it managed. Failure to release the old data causes memory leak. The default constructed Data manages null memory, so calling fastSet on it is fine. Because `Data ret = defaultValue;` malloc new memory, we might have better performance without it.
This commit is contained in:
parent
3e6b1ffe92
commit
b7a6b77789
|
@ -324,7 +324,7 @@ Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||||
encodedData = (const char*)(node->FirstChild()->Value());
|
encodedData = (const char*)(node->FirstChild()->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
Data ret = defaultValue;
|
Data ret;
|
||||||
|
|
||||||
if (encodedData)
|
if (encodedData)
|
||||||
{
|
{
|
||||||
|
@ -335,6 +335,10 @@ Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue)
|
||||||
ret.fastSet(decodedData, decodedDataLen);
|
ret.fastSet(decodedData, decodedDataLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
if (doc) delete doc;
|
if (doc) delete doc;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue