From 06de34a0333e6ad5ee2bfbe4d12030e036020593 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 2 Mar 2026 20:10:48 +0000 Subject: [PATCH] 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. --- src/rpc/server.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 0894ba1cdfe..b551c467ddb 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -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; } }