Skip to content

Commit 5a6f768

Browse files
Use unique_ptr for httpRPCTimerInterface (HTTPRPCTimerInterface)
1 parent 860e912 commit 5a6f768

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/httprpc.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class HTTPRPCTimerInterface : public RPCTimerInterface
6262
/* Pre-base64-encoded authentication token */
6363
static std::string strRPCUserColonPass;
6464
/* Stored RPC timer interface (for unregistration) */
65-
static HTTPRPCTimerInterface* httpRPCTimerInterface = nullptr;
65+
static std::unique_ptr<HTTPRPCTimerInterface> httpRPCTimerInterface;
6666

6767
static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const UniValue& id)
6868
{
@@ -238,8 +238,8 @@ bool StartHTTPRPC()
238238
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
239239
#endif
240240
assert(EventBase());
241-
httpRPCTimerInterface = new HTTPRPCTimerInterface(EventBase());
242-
RPCSetTimerInterface(httpRPCTimerInterface);
241+
httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>(new HTTPRPCTimerInterface(EventBase()));
242+
RPCSetTimerInterface(httpRPCTimerInterface.get());
243243
return true;
244244
}
245245

@@ -253,8 +253,7 @@ void StopHTTPRPC()
253253
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n");
254254
UnregisterHTTPHandler("/", true);
255255
if (httpRPCTimerInterface) {
256-
RPCUnsetTimerInterface(httpRPCTimerInterface);
257-
delete httpRPCTimerInterface;
258-
httpRPCTimerInterface = nullptr;
256+
RPCUnsetTimerInterface(httpRPCTimerInterface.get());
257+
httpRPCTimerInterface.reset();
259258
}
260259
}

0 commit comments

Comments
 (0)