diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 72080c4e..8b29b592 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -75,9 +75,7 @@ DownloadFactory::~DownloadFactory() { torrent::this_thread::scheduler()->erase(&m_task_load); torrent::this_thread::scheduler()->erase(&m_task_commit); - delete m_stream; delete m_object; - m_stream = NULL; } void @@ -92,7 +90,7 @@ DownloadFactory::load_raw_data(const std::string& input) { if (m_stream) throw torrent::internal_error("DownloadFactory::load*() called on an object with m_stream != NULL"); - m_stream = new std::stringstream(input); + m_stream.reset(new std::stringstream(input)); m_loaded = true; } @@ -108,7 +106,7 @@ DownloadFactory::receive_load() { if (is_network_uri(m_uri)) { // Http handling here. - m_stream = new std::stringstream; + m_stream.reset(new std::stringstream); HttpQueue::iterator itr = m_manager->http_queue()->insert(m_uri, m_stream); @@ -119,7 +117,7 @@ DownloadFactory::receive_load() { } else if (is_magnet_uri(m_uri)) { // DEBUG: Use m_object. - m_stream = new std::stringstream(); + m_stream.reset(new std::stringstream()); *m_stream << "d10:magnet-uri" << m_uri.length() << ":" << m_uri << "e"; m_variables["tied_to_file"] = (int64_t)false; @@ -171,8 +169,8 @@ DownloadFactory::receive_success() { else tracker_key = random() % (std::numeric_limits::max() - 1) + 1; - Download* download = m_stream != NULL ? - m_manager->download_list()->create(m_stream, tracker_key, m_printLog) : + Download* download = m_stream != nullptr ? + m_manager->download_list()->create(m_stream.get(), tracker_key, m_printLog) : m_manager->download_list()->create(m_object, tracker_key, m_printLog); m_object = NULL; diff --git a/src/core/download_factory.h b/src/core/download_factory.h index f1ea2f8c..71513807 100644 --- a/src/core/download_factory.h +++ b/src/core/download_factory.h @@ -62,9 +62,9 @@ private: void initialize_rtorrent(Download* download, torrent::Object* rtorrent); - Manager* m_manager; - std::iostream* m_stream{}; - torrent::Object* m_object{}; + Manager* m_manager; + std::shared_ptr m_stream; + torrent::Object* m_object{}; bool m_commited{}; bool m_loaded{}; diff --git a/src/core/http_queue.cc b/src/core/http_queue.cc index 04e2b504..7568c138 100644 --- a/src/core/http_queue.cc +++ b/src/core/http_queue.cc @@ -8,7 +8,7 @@ namespace core { HttpQueue::iterator -HttpQueue::insert(const std::string& url, std::iostream* stream) { +HttpQueue::insert(const std::string& url, std::shared_ptr stream) { auto itr = base_type::insert(end(), torrent::net::HttpGet(url, stream)); itr->add_done_slot([this, itr]() { erase(itr); }); @@ -16,6 +16,7 @@ HttpQueue::insert(const std::string& url, std::iostream* stream) { torrent::net_thread::http_stack()->start_get(*itr); + // TODO: Move above? for (auto& slot : m_signal_insert) slot(*itr); @@ -27,6 +28,7 @@ HttpQueue::erase(iterator signal_itr) { for (const auto& slot : m_signal_erase) slot(*signal_itr); + signal_itr->close(); base_type::erase(signal_itr); } diff --git a/src/core/http_queue.h b/src/core/http_queue.h index 4ea61ca2..5f107063 100644 --- a/src/core/http_queue.h +++ b/src/core/http_queue.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,7 @@ public: // // Consider adding a flag to indicate whetever HttpQueue should // delete the stream. - iterator insert(const std::string& url, std::iostream* stream); + iterator insert(const std::string& url, std::shared_ptr stream); void erase(iterator itr); void clear();