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:
will
2026-03-02 20:10:48 +00:00
parent d4d64ae739
commit 06de34a033

View File

@@ -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;
}
}