Commit 3f4f7b0a authored by Max Kellermann's avatar Max Kellermann

lib/upnp/Discovery: protect "downloaders" accesses with mutex

parent 0a4b866d
...@@ -42,12 +42,14 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent, ...@@ -42,12 +42,14 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))), expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))),
request(*parent.curl, url.c_str(), *this) request(*parent.curl, url.c_str(), *this)
{ {
const std::lock_guard<Mutex> protect(parent.mutex);
parent.downloaders.push_back(*this); parent.downloaders.push_back(*this);
} }
void void
UPnPDeviceDirectory::Downloader::Destroy() noexcept UPnPDeviceDirectory::Downloader::Destroy() noexcept
{ {
const std::lock_guard<Mutex> protect(parent.mutex);
parent.downloaders.erase_and_dispose(parent.downloaders.iterator_to(*this), parent.downloaders.erase_and_dispose(parent.downloaders.iterator_to(*this),
DeleteDisposer()); DeleteDisposer());
} }
...@@ -265,6 +267,7 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop, ...@@ -265,6 +267,7 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop,
UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept
{ {
BlockingCall(GetEventLoop(), [this](){ BlockingCall(GetEventLoop(), [this](){
const std::lock_guard<Mutex> protect(mutex);
downloaders.clear_and_dispose(DeleteDisposer()); downloaders.clear_and_dispose(DeleteDisposer());
}); });
} }
......
...@@ -137,9 +137,15 @@ class UPnPDeviceDirectory final : UpnpCallback { ...@@ -137,9 +137,15 @@ class UPnPDeviceDirectory final : UpnpCallback {
Mutex mutex; Mutex mutex;
/**
* Protected by #mutex.
*/
boost::intrusive::list<Downloader, boost::intrusive::list<Downloader,
boost::intrusive::constant_time_size<false>> downloaders; boost::intrusive::constant_time_size<false>> downloaders;
/**
* Protected by #mutex.
*/
std::list<ContentDirectoryDescriptor> directories; std::list<ContentDirectoryDescriptor> directories;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment