diff --git a/daemon/connect/Connection.cpp b/daemon/connect/Connection.cpp index 8422d80e..85531ece 100644 --- a/daemon/connect/Connection.cpp +++ b/daemon/connect/Connection.cpp @@ -455,7 +455,7 @@ char* Connection::ReadLine(char* buffer, int size, int* bytesReadOut) return buffer; } -Connection* Connection::Accept() +std::unique_ptr Connection::Accept() { debug("Accepting connection"); @@ -474,9 +474,7 @@ Connection* Connection::Accept() return nullptr; } - Connection* con = new Connection(socket, m_tls); - - return con; + return std::make_unique(socket, m_tls); } int Connection::TryRecv(char* buffer, int size) diff --git a/daemon/connect/Connection.h b/daemon/connect/Connection.h index a418c67e..3f0c722f 100644 --- a/daemon/connect/Connection.h +++ b/daemon/connect/Connection.h @@ -97,7 +97,6 @@ protected: #endif #endif - Connection(SOCKET socket, bool tls); void ReportError(const char* msgPrefix, const char* msgArg, bool PrintErrCode, int herrno = 0, const char* herrMsg = nullptr); virtual void PrintError(const char* errMsg); bool DoConnect(); @@ -115,6 +114,7 @@ protected: public: Connection(const char* host, int port, bool tls); + Connection(SOCKET socket, bool tls); virtual ~Connection(); static void Init(); static void Final(); @@ -127,7 +127,7 @@ public: char* ReadLine(char* buffer, int size, int* bytesRead); void ReadBuffer(char** buffer, int *bufLen); int WriteLine(const char* buffer); - Connection* Accept(); + std::unique_ptr Accept(); void Cancel(); const char* GetHost() { return m_host; } int GetPort() { return m_port; } diff --git a/daemon/feed/FeedCoordinator.cpp b/daemon/feed/FeedCoordinator.cpp index 0e00ec16..22581db6 100644 --- a/daemon/feed/FeedCoordinator.cpp +++ b/daemon/feed/FeedCoordinator.cpp @@ -362,16 +362,16 @@ void FeedCoordinator::FeedCompleted(FeedDownloader* feedDownloader) FeedScriptController::ExecuteScripts( !Util::EmptyStr(feedInfo->GetFeedScript()) ? feedInfo->GetFeedScript(): g_Options->GetFeedScript(), feedInfo->GetOutputFilename(), feedInfo->GetId()); - FeedFile* feedFile = FeedFile::Create(feedInfo->GetOutputFilename()); + std::unique_ptr feedFile = std::make_unique(feedInfo->GetOutputFilename()); FileSystem::DeleteFile(feedInfo->GetOutputFilename()); NzbList addedNzbs; m_downloadsMutex.Lock(); - if (feedFile) + if (feedFile->Parse()) { ProcessFeed(feedInfo, feedFile->GetFeedItemInfos(), &addedNzbs); - delete feedFile; + feedFile.reset(); } feedInfo->SetLastUpdate(Util::CurrentTime()); feedInfo->SetForce(false); @@ -398,10 +398,11 @@ void FeedCoordinator::FilterFeed(FeedInfo* feedInfo, FeedItemInfos* feedItemInfo { debug("Filtering feed %s", feedInfo->GetName()); - FeedFilter* feedFilter = nullptr; - if (feedInfo->GetFilter() && strlen(feedInfo->GetFilter()) > 0) + std::unique_ptr feedFilter; + + if (!Util::EmptyStr(feedInfo->GetFilter())) { - feedFilter = new FeedFilter(feedInfo->GetFilter()); + feedFilter = std::make_unique(feedInfo->GetFilter()); } for (FeedItemInfo& feedItemInfo : feedItemInfos) @@ -420,8 +421,6 @@ void FeedCoordinator::FilterFeed(FeedInfo* feedInfo, FeedItemInfos* feedItemInfo feedFilter->Match(feedItemInfo); } } - - delete feedFilter; } void FeedCoordinator::ProcessFeed(FeedInfo* feedInfo, FeedItemInfos* feedItemInfos, NzbList* addedNzbs) @@ -525,7 +524,7 @@ bool FeedCoordinator::PreviewFeed(int id, const char* name, const char* url, con { debug("Preview feed %s", name); - FeedInfo* feedInfo = new FeedInfo(id, name, url, backlog, interval, + std::unique_ptr feedInfo = std::make_unique(id, name, url, backlog, interval, filter, pauseNzb, category, priority, feedScript); feedInfo->SetPreview(true); @@ -564,7 +563,7 @@ bool FeedCoordinator::PreviewFeed(int id, const char* name, const char* url, con } } - StartFeedDownload(feedInfo, true); + StartFeedDownload(feedInfo.get(), true); m_downloadsMutex.Unlock(); // wait until the download in a separate thread completes @@ -575,27 +574,26 @@ bool FeedCoordinator::PreviewFeed(int id, const char* name, const char* url, con // now can process the feed - FeedFile* feedFile = nullptr; + std::unique_ptr feedFile; if (feedInfo->GetStatus() == FeedInfo::fsFinished) { FeedScriptController::ExecuteScripts( !Util::EmptyStr(feedInfo->GetFeedScript()) ? feedInfo->GetFeedScript(): g_Options->GetFeedScript(), feedInfo->GetOutputFilename(), feedInfo->GetId()); - feedFile = FeedFile::Create(feedInfo->GetOutputFilename()); + feedFile = std::make_unique(feedInfo->GetOutputFilename()); } FileSystem::DeleteFile(feedInfo->GetOutputFilename()); - if (!feedFile) + if (!feedFile || !feedFile->Parse()) { - delete feedInfo; return false; } feedItemInfos = feedFile->GetFeedItemInfos(); feedItemInfos->Retain(); - delete feedFile; + feedFile.reset(); for (FeedItemInfo& feedItemInfo : feedItemInfos) { @@ -608,8 +606,8 @@ bool FeedCoordinator::PreviewFeed(int id, const char* name, const char* url, con } } - FilterFeed(feedInfo, feedItemInfos); - delete feedInfo; + FilterFeed(feedInfo.get(), feedItemInfos); + feedInfo.reset(); if (cacheTimeSec > 0 && *cacheId != '\0' && !hasCache) { diff --git a/daemon/feed/FeedFile.cpp b/daemon/feed/FeedFile.cpp index 4646defb..c09e3719 100644 --- a/daemon/feed/FeedFile.cpp +++ b/daemon/feed/FeedFile.cpp @@ -91,7 +91,7 @@ void FeedFile::ParseSubject(FeedItemInfo& feedItemInfo) } #ifdef WIN32 -FeedFile* FeedFile::Create(const char* fileName) +bool FeedFile::Parse() { CoInitialize(nullptr); @@ -101,7 +101,7 @@ FeedFile* FeedFile::Create(const char* fileName) hr = doc.CreateInstance(MSXML::CLSID_DOMDocument); if (FAILED(hr)) { - return nullptr; + return false; } // Load the XML document file... @@ -129,17 +129,12 @@ FeedFile* FeedFile::Create(const char* fileName) _bstr_t r(doc->GetparseError()->reason); const char* errMsg = r; error("Error parsing rss feed: %s", errMsg); - return nullptr; + return false; } - FeedFile* file = new FeedFile(fileName); - if (!file->ParseFeed(doc)) - { - delete file; - file = nullptr; - } + bool ok = ParseFeed(doc); - return file; + return ok; } void FeedFile::EncodeUrl(const char* filename, char* url, int bufLen) @@ -378,10 +373,8 @@ bool FeedFile::ParseFeed(IUnknown* nzb) #else -FeedFile* FeedFile::Create(const char* fileName) +bool FeedFile::Parse() { - FeedFile* file = new FeedFile(fileName); - xmlSAXHandler SAX_handler = {0}; SAX_handler.startElement = reinterpret_cast(SAX_StartElement); SAX_handler.endElement = reinterpret_cast(SAX_EndElement); @@ -389,18 +382,17 @@ FeedFile* FeedFile::Create(const char* fileName) SAX_handler.error = reinterpret_cast(SAX_error); SAX_handler.getEntity = reinterpret_cast(SAX_getEntity); - file->m_ignoreNextError = false; + m_ignoreNextError = false; - int ret = xmlSAXUserParseFile(&SAX_handler, file, fileName); + int ret = xmlSAXUserParseFile(&SAX_handler, this, m_fileName); if (ret != 0) { error("Failed to parse rss feed"); - delete file; - file = nullptr; + return false; } - return file; + return true; } void FeedFile::Parse_StartElement(const char *name, const char **atts) diff --git a/daemon/feed/FeedFile.h b/daemon/feed/FeedFile.h index 98b39a6d..63ce2340 100644 --- a/daemon/feed/FeedFile.h +++ b/daemon/feed/FeedFile.h @@ -35,7 +35,6 @@ private: FeedItemInfos* m_feedItemInfos; CString m_fileName; - FeedFile(const char* fileName); void ParseSubject(FeedItemInfo& feedItemInfo); #ifdef WIN32 bool ParseFeed(IUnknown* nzb); @@ -57,8 +56,9 @@ private: #endif public: + FeedFile(const char* fileName); virtual ~FeedFile(); - static FeedFile* Create(const char* fileName); + bool Parse(); FeedItemInfos* GetFeedItemInfos() { return m_feedItemInfos; } void LogDebugInfo(); diff --git a/daemon/queue/QueueEditor.cpp b/daemon/queue/QueueEditor.cpp index a5cd0f22..e64af0a2 100644 --- a/daemon/queue/QueueEditor.cpp +++ b/daemon/queue/QueueEditor.cpp @@ -376,9 +376,12 @@ bool QueueEditor::EditList(DownloadQueue* downloadQueue, IdList* idList, NameLis m_downloadQueue = downloadQueue; bool ok = true; + std::unique_ptr nameIdList; + if (nameList) { - idList = new IdList(); + nameIdList = std::make_unique(); + idList = nameIdList.get(); ok = BuildIdListFromNameList(idList, nameList, matchMode, action); } @@ -386,11 +389,6 @@ bool QueueEditor::EditList(DownloadQueue* downloadQueue, IdList* idList, NameLis m_downloadQueue->Save(); - if (nameList) - { - delete idList; - } - return ok; } @@ -714,13 +712,12 @@ bool QueueEditor::BuildIdListFromNameList(IdList* idList, NameList* nameList, Do for (CString& name : nameList) { - RegEx *regEx = nullptr; + std::unique_ptr regEx; if (matchMode == DownloadQueue::mmRegEx) { - regEx = new RegEx(name); + regEx = std::make_unique(name); if (!regEx->IsValid()) { - delete regEx; return false; } } @@ -759,8 +756,6 @@ bool QueueEditor::BuildIdListFromNameList(IdList* idList, NameList* nameList, Do } } - delete regEx; - if (!found && (matchMode == DownloadQueue::mmName)) { return false; diff --git a/daemon/remote/BinRpc.cpp b/daemon/remote/BinRpc.cpp index c409015c..52881905 100644 --- a/daemon/remote/BinRpc.cpp +++ b/daemon/remote/BinRpc.cpp @@ -210,64 +210,64 @@ void BinRpcProcessor::Dispatch() return; } - BinCommand* command = nullptr; + std::unique_ptr command; switch (ntohl(m_messageBase.m_type)) { case rrDownload: - command = new DownloadBinCommand(); + command = std::make_unique(); break; case rrList: - command = new ListBinCommand(); + command = std::make_unique(); break; case rrLog: - command = new LogBinCommand(); + command = std::make_unique(); break; case rrPauseUnpause: - command = new PauseUnpauseBinCommand(); + command = std::make_unique(); break; case rrEditQueue: - command = new EditQueueBinCommand(); + command = std::make_unique(); break; case rrSetDownloadRate: - command = new SetDownloadRateBinCommand(); + command = std::make_unique(); break; case rrDumpDebug: - command = new DumpDebugBinCommand(); + command = std::make_unique(); break; case rrShutdown: - command = new ShutdownBinCommand(); + command = std::make_unique(); break; case rrReload: - command = new ReloadBinCommand(); + command = std::make_unique(); break; case rrVersion: - command = new VersionBinCommand(); + command = std::make_unique(); break; case rrPostQueue: - command = new PostQueueBinCommand(); + command = std::make_unique(); break; case rrWriteLog: - command = new WriteLogBinCommand(); + command = std::make_unique(); break; case rrScan: - command = new ScanBinCommand(); + command = std::make_unique(); break; case rrHistory: - command = new HistoryBinCommand(); + command = std::make_unique(); break; default: @@ -280,7 +280,6 @@ void BinRpcProcessor::Dispatch() command->SetConnection(m_connection); command->SetMessageBase(&m_messageBase); command->Execute(); - delete command; } } diff --git a/daemon/remote/RemoteServer.cpp b/daemon/remote/RemoteServer.cpp index ba3c3a25..ec3dcdd4 100644 --- a/daemon/remote/RemoteServer.cpp +++ b/daemon/remote/RemoteServer.cpp @@ -71,12 +71,12 @@ void RemoteServer::Run() } // Accept connections and store the new Connection - Connection* acceptedConnection = nullptr; + std::unique_ptr acceptedConnection; if (bind) { acceptedConnection = m_connection->Accept(); } - if (!bind || acceptedConnection == nullptr) + if (!bind || !acceptedConnection) { // Remote server could not bind or accept connection, waiting 1/2 sec and try again if (IsStopped()) @@ -90,7 +90,7 @@ void RemoteServer::Run() RequestProcessor* commandThread = new RequestProcessor(); commandThread->SetAutoDestroy(true); - commandThread->SetConnection(acceptedConnection); + commandThread->SetConnection(std::move(acceptedConnection)); #ifndef DISABLE_TLS commandThread->SetTls(m_tls); #endif @@ -124,7 +124,6 @@ void RemoteServer::Stop() RequestProcessor::~RequestProcessor() { m_connection->Disconnect(); - delete m_connection; } void RequestProcessor::Run() @@ -154,7 +153,7 @@ void RequestProcessor::Run() // binary request received ok = true; BinRpcProcessor processor; - processor.SetConnection(m_connection); + processor.SetConnection(m_connection.get()); processor.Execute(); } else if (!strncmp((char*)&signature, "POST", 4) || @@ -185,7 +184,7 @@ void RequestProcessor::Run() debug("url: %s", url); WebProcessor processor; - processor.SetConnection(m_connection); + processor.SetConnection(m_connection.get()); processor.SetUrl(url); processor.SetHttpMethod(httpMethod); processor.Execute(); diff --git a/daemon/remote/RemoteServer.h b/daemon/remote/RemoteServer.h index b7180c0d..48d1b846 100644 --- a/daemon/remote/RemoteServer.h +++ b/daemon/remote/RemoteServer.h @@ -46,13 +46,13 @@ class RequestProcessor : public Thread { private: bool m_tls; - Connection* m_connection; + std::unique_ptr m_connection; public: ~RequestProcessor(); virtual void Run(); void SetTls(bool tls) { m_tls = tls; } - void SetConnection(Connection* connection) { m_connection = connection; } + void SetConnection(std::unique_ptr&& connection) { m_connection = std::move(connection); } }; #endif diff --git a/daemon/remote/XmlRpc.cpp b/daemon/remote/XmlRpc.cpp index f2790709..4fccd41e 100644 --- a/daemon/remote/XmlRpc.cpp +++ b/daemon/remote/XmlRpc.cpp @@ -414,7 +414,7 @@ void XmlRpcProcessor::Dispatch() } else { - XmlCommand* command = CreateCommand(methodName); + std::unique_ptr command = CreateCommand(methodName); command->SetRequest(request); command->SetProtocol(m_protocol); command->SetHttpMethod(m_httpMethod); @@ -422,7 +422,6 @@ void XmlRpcProcessor::Dispatch() command->PrepareParams(); command->Execute(); BuildResponse(command->GetResponse(), command->GetCallbackFunc(), command->GetFault(), requestId); - delete command; } } @@ -451,7 +450,7 @@ void XmlRpcProcessor::MutliCall() WebUtil::XmlParseTagValue(nameEnd, "string", methodName, sizeof(methodName), nullptr); debug("MutliCall, MethodName=%s", methodName); - XmlCommand* command = CreateCommand(methodName); + std::unique_ptr command = CreateCommand(methodName); command->SetRequest(requestPtr); command->Execute(); @@ -471,21 +470,18 @@ void XmlRpcProcessor::MutliCall() response.Append(""); } - delete command; - requestPtr = callEnd + 9; //strlen("") callEnd = strstr(requestPtr, ""); } if (error) { - XmlCommand* command = new ErrorXmlCommand(4, "Parse error"); - command->SetRequest(m_request); - command->SetProtocol(rpXmlRpc); - command->PrepareParams(); - command->Execute(); - BuildResponse(command->GetResponse(), "", command->GetFault(), nullptr); - delete command; + ErrorXmlCommand command(4, "Parse error"); + command.SetRequest(m_request); + command.SetProtocol(rpXmlRpc); + command.PrepareParams(); + command.Execute(); + BuildResponse(command.GetResponse(), "", command.GetFault(), nullptr); } else { @@ -548,187 +544,187 @@ void XmlRpcProcessor::BuildResponse(const char* response, const char* callbackFu m_contentType = xmlRpc ? "text/xml" : "application/json"; } -XmlCommand* XmlRpcProcessor::CreateCommand(const char* methodName) +std::unique_ptr XmlRpcProcessor::CreateCommand(const char* methodName) { - XmlCommand* command = nullptr; + std::unique_ptr command; if (m_userAccess == uaAdd && !(!strcasecmp(methodName, "append") || !strcasecmp(methodName, "appendurl") || !strcasecmp(methodName, "version"))) { - command = new ErrorXmlCommand(401, "Access denied"); + command = std::make_unique(401, "Access denied"); warn("Received request \"%s\" from add-user, access denied", methodName); } else if (m_userAccess == uaRestricted && !strcasecmp(methodName, "saveconfig")) { - command = new ErrorXmlCommand(401, "Access denied"); + command = std::make_unique(401, "Access denied"); warn("Received request \"%s\" from restricted user, access denied", methodName); } else if (!strcasecmp(methodName, "pause") || !strcasecmp(methodName, "pausedownload") || !strcasecmp(methodName, "pausedownload2")) { - command = new PauseUnpauseXmlCommand(true, PauseUnpauseXmlCommand::paDownload); + command = std::make_unique(true, PauseUnpauseXmlCommand::paDownload); } else if (!strcasecmp(methodName, "resume") || !strcasecmp(methodName, "resumedownload") || !strcasecmp(methodName, "resumedownload2")) { - command = new PauseUnpauseXmlCommand(false, PauseUnpauseXmlCommand::paDownload); + command = std::make_unique(false, PauseUnpauseXmlCommand::paDownload); } else if (!strcasecmp(methodName, "shutdown")) { - command = new ShutdownXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "reload")) { - command = new ReloadXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "version")) { - command = new VersionXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "dump")) { - command = new DumpDebugXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "rate")) { - command = new SetDownloadRateXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "status")) { - command = new StatusXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "log")) { - command = new LogXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "listfiles")) { - command = new ListFilesXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "listgroups")) { - command = new ListGroupsXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "editqueue")) { - command = new EditQueueXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "append") || !strcasecmp(methodName, "appendurl")) { - command = new DownloadXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "postqueue")) { - command = new PostQueueXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "writelog")) { - command = new WriteLogXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "clearlog")) { - command = new ClearLogXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "loadlog")) { - command = new LoadLogXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "scan")) { - command = new ScanXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "pausepost")) { - command = new PauseUnpauseXmlCommand(true, PauseUnpauseXmlCommand::paPostProcess); + command = std::make_unique(true, PauseUnpauseXmlCommand::paPostProcess); } else if (!strcasecmp(methodName, "resumepost")) { - command = new PauseUnpauseXmlCommand(false, PauseUnpauseXmlCommand::paPostProcess); + command = std::make_unique(false, PauseUnpauseXmlCommand::paPostProcess); } else if (!strcasecmp(methodName, "pausescan")) { - command = new PauseUnpauseXmlCommand(true, PauseUnpauseXmlCommand::paScan); + command = std::make_unique(true, PauseUnpauseXmlCommand::paScan); } else if (!strcasecmp(methodName, "resumescan")) { - command = new PauseUnpauseXmlCommand(false, PauseUnpauseXmlCommand::paScan); + command = std::make_unique(false, PauseUnpauseXmlCommand::paScan); } else if (!strcasecmp(methodName, "scheduleresume")) { - command = new ScheduleResumeXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "history")) { - command = new HistoryXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "urlqueue")) { - command = new UrlQueueXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "config")) { - command = new ConfigXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "loadconfig")) { - command = new LoadConfigXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "saveconfig")) { - command = new SaveConfigXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "configtemplates")) { - command = new ConfigTemplatesXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "viewfeed")) { - command = new ViewFeedXmlCommand(false); + command = std::make_unique(false); } else if (!strcasecmp(methodName, "previewfeed")) { - command = new ViewFeedXmlCommand(true); + command = std::make_unique(true); } else if (!strcasecmp(methodName, "fetchfeed")) { - command = new FetchFeedXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "editserver")) { - command = new EditServerXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "readurl")) { - command = new ReadUrlXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "checkupdates")) { - command = new CheckUpdatesXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "startupdate")) { - command = new StartUpdateXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "logupdate")) { - command = new LogUpdateXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "servervolumes")) { - command = new ServerVolumesXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "resetservervolume")) { - command = new ResetServerVolumeXmlCommand(); + command = std::make_unique(); } else if (!strcasecmp(methodName, "testserver")) { - command = new TestServerXmlCommand(); + command = std::make_unique(); } else { - command = new ErrorXmlCommand(1, "Invalid procedure"); + command = std::make_unique(1, "Invalid procedure"); } return command; @@ -3040,7 +3036,7 @@ void ReadUrlXmlCommand::Execute() num++; } - WebDownloader* downloader = new WebDownloader(); + std::unique_ptr downloader = std::make_unique(); downloader->SetUrl(url); downloader->SetForce(true); downloader->SetRetry(false); @@ -3051,7 +3047,7 @@ void ReadUrlXmlCommand::Execute() WebDownloader::EStatus status = downloader->DownloadWithRedirects(5); bool ok = status == WebDownloader::adFinished; - delete downloader; + downloader.reset(); if (ok) { @@ -3382,18 +3378,16 @@ void TestServerXmlCommand::Execute() } NewsServer server(0, true, "test server", host, port, username, password, false, encryption, cipher, 1, 0, 0, 0); - TestConnection* connection = new TestConnection(&server, this); - connection->SetTimeout(timeout == 0 ? g_Options->GetArticleTimeout() : timeout); - connection->SetSuppressErrors(false); + TestConnection connection(&server, this); + connection.SetTimeout(timeout == 0 ? g_Options->GetArticleTimeout() : timeout); + connection.SetSuppressErrors(false); - bool ok = connection->Connect(); + bool ok = connection.Connect(); BString<1024> content(IsJson() ? JSON_RESPONSE_STR_BODY : XML_RESPONSE_STR_BODY, ok ? "" : m_errText.Empty() ? "Unknown error" : *m_errText); AppendResponse(content); - - delete connection; } void TestServerXmlCommand::PrintError(const char* errMsg) diff --git a/daemon/remote/XmlRpc.h b/daemon/remote/XmlRpc.h index ca523c33..91459ac2 100644 --- a/daemon/remote/XmlRpc.h +++ b/daemon/remote/XmlRpc.h @@ -66,7 +66,7 @@ private: StringBuilder m_response; void Dispatch(); - XmlCommand* CreateCommand(const char* methodName); + std::unique_ptr CreateCommand(const char* methodName); void MutliCall(); void BuildResponse(const char* response, const char* callbackFunc, bool fault, const char* requestId); diff --git a/daemon/util/Script.cpp b/daemon/util/Script.cpp index 195fc5fb..d6241592 100644 --- a/daemon/util/Script.cpp +++ b/daemon/util/Script.cpp @@ -344,10 +344,10 @@ int ScriptController::Execute() #ifdef CHILD_WATCHDOG debug("Creating child watchdog"); - ChildWatchDog* watchDog = new ChildWatchDog(); - watchDog->SetAutoDestroy(false); - watchDog->SetProcessId(m_processId); - watchDog->Start(); + ChildWatchDog watchDog; + watchDog.SetAutoDestroy(false); + watchDog.SetProcessId(m_processId); + watchDog.Start(); #endif CharBuffer buf(1024 * 10); @@ -363,7 +363,7 @@ int ScriptController::Execute() if (!childConfirmed) { childConfirmed = true; - watchDog->Stop(); + watchDog.Stop(); debug("Child confirmed"); continue; } @@ -382,13 +382,12 @@ int ScriptController::Execute() debug("Destroying WatchDog"); if (!childConfirmed) { - watchDog->Stop(); + watchDog.Stop(); } - while (watchDog->IsRunning()) + while (watchDog.IsRunning()) { usleep(5 * 1000); } - delete watchDog; #endif if (m_readpipe)