@@ -138,7 +138,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
138138// ! Work queue for handling longer requests off the event loop thread
139139static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr };
140140// ! Handlers for (sub)paths
141- static std::vector<HTTPPathHandler> pathHandlers;
141+ static Mutex g_httppathhandlers_mutex;
142+ static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY (g_httppathhandlers_mutex);
142143// ! Bound listening sockets
143144static std::vector<evhttp_bound_socket *> boundSockets;
144145
@@ -239,6 +240,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
239240 // Find registered handler for prefix
240241 std::string strURI = hreq->GetURI ();
241242 std::string path;
243+ LOCK (g_httppathhandlers_mutex);
242244 std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin ();
243245 std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end ();
244246 for (; i != iend; ++i) {
@@ -633,11 +635,13 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() const
633635void RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
634636{
635637 LogPrint (BCLog::HTTP, " Registering HTTP handler for %s (exactmatch %d)\n " , prefix, exactMatch);
638+ LOCK (g_httppathhandlers_mutex);
636639 pathHandlers.push_back (HTTPPathHandler (prefix, exactMatch, handler));
637640}
638641
639642void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
640643{
644+ LOCK (g_httppathhandlers_mutex);
641645 std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin ();
642646 std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end ();
643647 for (; i != iend; ++i)
0 commit comments