fix: resolve some memory leaks (#4939)

- In wallet/rpcdump memory the leak would happen, if wallet is not correct JSON
 - In BLS the leak would happen, if object hasn't been pushed in queue by some reason. Need to remove temporary object also
This commit is contained in:
Konstantin Akimov 2022-08-06 00:13:42 +07:00 committed by GitHub
parent 0835e4c307
commit 7b9f0acbdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -269,7 +269,13 @@ struct Aggregator : public std::enable_shared_from_this<Aggregator<T>> {
void PushAggQueue(const T& v)
{
aggQueue.push(new T(v));
auto copyT = new T(v);
try {
aggQueue.push(copyT);
} catch (...) {
delete copyT;
throw;
}
if (++aggQueueSize >= batchSize) {
// we've collected enough intermediate results to form a new batch.

View File

@ -730,12 +730,13 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
}
} else {
// json
char* buffer = new char [nFilesize];
file.read(buffer, nFilesize);
UniValue data(UniValue::VOBJ);
if(!data.read(buffer))
throw JSONRPCError(RPC_TYPE_ERROR, "Cannot parse Electrum wallet export file");
delete[] buffer;
{
auto buffer = std::make_unique<char[]>(nFilesize);
file.read(buffer.get(), nFilesize);
if(!data.read(buffer.get()))
throw JSONRPCError(RPC_TYPE_ERROR, "Cannot parse Electrum wallet export file");
}
std::vector<std::string> vKeys = data.getKeys();