Skip to content

Commit

Permalink
Use unique_ptr for httpRPCTimerInterface (HTTPRPCTimerInterface)
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift committed Nov 9, 2017
1 parent 860e912 commit 5a6f768
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class HTTPRPCTimerInterface : public RPCTimerInterface
/* Pre-base64-encoded authentication token */
static std::string strRPCUserColonPass;
/* Stored RPC timer interface (for unregistration) */
static HTTPRPCTimerInterface* httpRPCTimerInterface = nullptr;
static std::unique_ptr<HTTPRPCTimerInterface> httpRPCTimerInterface;

static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const UniValue& id)
{
Expand Down Expand Up @@ -238,8 +238,8 @@ bool StartHTTPRPC()
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
#endif
assert(EventBase());
httpRPCTimerInterface = new HTTPRPCTimerInterface(EventBase());
RPCSetTimerInterface(httpRPCTimerInterface);
httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>(new HTTPRPCTimerInterface(EventBase()));
RPCSetTimerInterface(httpRPCTimerInterface.get());
return true;
}

Expand All @@ -253,8 +253,7 @@ void StopHTTPRPC()
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n");
UnregisterHTTPHandler("/", true);
if (httpRPCTimerInterface) {
RPCUnsetTimerInterface(httpRPCTimerInterface);
delete httpRPCTimerInterface;
httpRPCTimerInterface = nullptr;
RPCUnsetTimerInterface(httpRPCTimerInterface.get());
httpRPCTimerInterface.reset();
}
}

0 comments on commit 5a6f768

Please sign in to comment.