Skip to content

Commit 93daf17

Browse files
practicalswiftrandom-zebra
authored andcommitted
Use unique_ptr for httpRPCTimerInterface (HTTPRPCTimerInterface)
1 parent 020ac16 commit 93daf17

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
@@ -59,7 +59,7 @@ class HTTPRPCTimerInterface : public RPCTimerInterface
5959
/* Pre-base64-encoded authentication token */
6060
static std::string strRPCUserColonPass;
6161
/* Stored RPC timer interface (for unregistration) */
62-
static HTTPRPCTimerInterface* httpRPCTimerInterface = 0;
62+
static std::unique_ptr<HTTPRPCTimerInterface> httpRPCTimerInterface;
6363

6464
static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const UniValue& id)
6565
{
@@ -233,8 +233,8 @@ bool StartHTTPRPC()
233233
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
234234
#endif
235235
assert(EventBase());
236-
httpRPCTimerInterface = new HTTPRPCTimerInterface(EventBase());
237-
RPCSetTimerInterface(httpRPCTimerInterface);
236+
httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>(new HTTPRPCTimerInterface(EventBase()));
237+
RPCSetTimerInterface(httpRPCTimerInterface.get());
238238
return true;
239239
}
240240

@@ -248,8 +248,7 @@ void StopHTTPRPC()
248248
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n");
249249
UnregisterHTTPHandler("/", true);
250250
if (httpRPCTimerInterface) {
251-
RPCUnsetTimerInterface(httpRPCTimerInterface);
252-
delete httpRPCTimerInterface;
253-
httpRPCTimerInterface = 0;
251+
RPCUnsetTimerInterface(httpRPCTimerInterface.get());
252+
httpRPCTimerInterface.reset();
254253
}
255254
}

0 commit comments

Comments
 (0)