mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
rpc: erase empty map entry in removeCommand
After removing the last CRPCCommand pointer for a given name, erase the now-empty vector from mapCommands. Without this, listCommands() returns the name of a fully removed command because it iterates mapCommands keys unconditionally. For example, when unloading the wallet the RPCs are deregistered, and this prevents getopenrpcinfo from returning non-existant RPCs.
This commit is contained in:
@@ -264,6 +264,9 @@ bool CRPCTable::removeCommand(const std::string& name, const CRPCCommand* pcmd)
|
||||
auto new_end = std::remove(it->second.begin(), it->second.end(), pcmd);
|
||||
if (it->second.end() != new_end) {
|
||||
it->second.erase(new_end, it->second.end());
|
||||
if (it->second.empty()) {
|
||||
mapCommands.erase(it);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user