download: fix leak
A shared_ptr as by value capture will keep the object alive
This commit is contained in:
parent
b58a9fb12e
commit
75d05b9448
|
@ -53,7 +53,7 @@ namespace tools
|
||||||
|
|
||||||
download_thread_control(const std::string &path, const std::string &uri, std::function<void(const std::string&, const std::string&, bool)> result_cb, std::function<bool(const std::string&, const std::string&, size_t, ssize_t)> progress_cb):
|
download_thread_control(const std::string &path, const std::string &uri, std::function<void(const std::string&, const std::string&, bool)> result_cb, std::function<bool(const std::string&, const std::string&, size_t, ssize_t)> progress_cb):
|
||||||
path(path), uri(uri), result_cb(result_cb), progress_cb(progress_cb), stop(false), stopped(false), success(false) {}
|
path(path), uri(uri), result_cb(result_cb), progress_cb(progress_cb), stop(false), stopped(false), success(false) {}
|
||||||
~download_thread_control() { if (thread.joinable()) thread.detach(); }
|
~download_thread_control() { if (thread.joinable()) { thread.detach(); thread = {}; } }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void download_thread(download_async_handle control)
|
static void download_thread(download_async_handle control)
|
||||||
|
@ -293,9 +293,13 @@ namespace tools
|
||||||
{
|
{
|
||||||
boost::lock_guard<boost::mutex> lock(control->mutex);
|
boost::lock_guard<boost::mutex> lock(control->mutex);
|
||||||
if (control->stopped)
|
if (control->stopped)
|
||||||
|
{
|
||||||
|
control->thread = {};
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
control->thread.join();
|
control->thread.join();
|
||||||
|
control->thread = {};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,10 +309,14 @@ namespace tools
|
||||||
{
|
{
|
||||||
boost::lock_guard<boost::mutex> lock(control->mutex);
|
boost::lock_guard<boost::mutex> lock(control->mutex);
|
||||||
if (control->stopped)
|
if (control->stopped)
|
||||||
|
{
|
||||||
|
control->thread = {};
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
control->stop = true;
|
control->stop = true;
|
||||||
}
|
}
|
||||||
control->thread.join();
|
control->thread.join();
|
||||||
|
control->thread = {};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue