@@ -143,7 +143,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
143143// ! Work queue for handling longer requests off the event loop thread
144144static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr };
145145// ! Handlers for (sub)paths
146- static std::vector<HTTPPathHandler> pathHandlers;
146+ static Mutex g_httppathhandlers_mutex;
147+ static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY (g_httppathhandlers_mutex);
147148// ! Bound listening sockets
148149static std::vector<evhttp_bound_socket *> boundSockets;
149150
@@ -244,6 +245,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
244245 // Find registered handler for prefix
245246 std::string strURI = hreq->GetURI ();
246247 std::string path;
248+ LOCK (g_httppathhandlers_mutex);
247249 std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin ();
248250 std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end ();
249251 for (; i != iend; ++i) {
@@ -642,11 +644,13 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() const
642644void RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
643645{
644646 LogPrint (BCLog::HTTP, " Registering HTTP handler for %s (exactmatch %d)\n " , prefix, exactMatch);
647+ LOCK (g_httppathhandlers_mutex);
645648 pathHandlers.push_back (HTTPPathHandler (prefix, exactMatch, handler));
646649}
647650
648651void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
649652{
653+ LOCK (g_httppathhandlers_mutex);
650654 std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin ();
651655 std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end ();
652656 for (; i != iend; ++i)
0 commit comments