Merge pull request #20293 from endjkv:fix-mem-leak-when-throw

* fix memory leak when exception is thrown
This commit is contained in:
xzvno 2021-06-27 05:01:31 +08:00 committed by GitHub
parent c95a56450d
commit 42d644ef91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1835,7 +1835,15 @@ void* TLSDataContainer::getData() const
{
// Create new data instance and save it to TLS storage
pData = createDataInstance();
getTlsStorage().setData(key_, pData);
try
{
getTlsStorage().setData(key_, pData);
}
catch (...)
{
deleteDataInstance(pData);
throw;
}
}
return pData;
}