diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index 16f0791c9..460ad5c5c 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -457,7 +457,7 @@ protected: size_t m_parallel_limit; // Variables exclusively used within thread - std::vector m_all_ongoing; + std::vector> m_all_ongoing; std::list m_queued_fetches; public: @@ -513,11 +513,8 @@ protected: u64 caller = req.fetch_request.caller; // Abort all ongoing fetches for the caller - for (std::vector::iterator - it = m_all_ongoing.begin(); - it != m_all_ongoing.end();) { + for (auto it = m_all_ongoing.begin(); it != m_all_ongoing.end();) { if ((*it)->getRequest().caller == caller) { - delete (*it); it = m_all_ongoing.erase(it); } else { ++it; @@ -552,17 +549,14 @@ protected: // Create ongoing fetch data and make a cURL handle // Set cURL options based on HTTPFetchRequest - HTTPFetchOngoing *ongoing = - new HTTPFetchOngoing(request, pool); + auto ongoing = std::make_unique(request, pool); // Initiate the connection (curl_multi_add_handle) CURLcode res = ongoing->start(m_multi); if (res == CURLE_OK) { - m_all_ongoing.push_back(ongoing); - } - else { + m_all_ongoing.push_back(std::move(ongoing)); + } else { httpfetch_deliver_result(*ongoing->complete(res)); - delete ongoing; } } } @@ -581,9 +575,8 @@ protected: } if (msg->msg == CURLMSG_DONE && found) { // m_all_ongoing[i] succeeded or failed. - HTTPFetchOngoing *ongoing = m_all_ongoing[i]; - httpfetch_deliver_result(*ongoing->complete(msg->data.result)); - delete ongoing; + HTTPFetchOngoing &ongoing = *m_all_ongoing[i]; + httpfetch_deliver_result(*ongoing.complete(msg->data.result)); m_all_ongoing.erase(m_all_ongoing.begin() + i); } } @@ -726,9 +719,6 @@ protected: } // Call curl_multi_remove_handle and cleanup easy handles - for (HTTPFetchOngoing *i : m_all_ongoing) { - delete i; - } m_all_ongoing.clear(); m_queued_fetches.clear();