From 3f4f7b0a53c00df5768f07fef5e444b60ad1a217 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 2 Jan 2018 14:55:57 +0100 Subject: [PATCH] lib/upnp/Discovery: protect "downloaders" accesses with mutex --- src/lib/upnp/Discovery.cxx | 3 +++ src/lib/upnp/Discovery.hxx | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 039f3a905..9a4b52712 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -42,12 +42,14 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent, expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))), request(*parent.curl, url.c_str(), *this) { + const std::lock_guard protect(parent.mutex); parent.downloaders.push_back(*this); } void UPnPDeviceDirectory::Downloader::Destroy() noexcept { + const std::lock_guard protect(parent.mutex); parent.downloaders.erase_and_dispose(parent.downloaders.iterator_to(*this), DeleteDisposer()); } @@ -265,6 +267,7 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop, UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept { BlockingCall(GetEventLoop(), [this](){ + const std::lock_guard protect(mutex); downloaders.clear_and_dispose(DeleteDisposer()); }); } diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 623b5d8dc..0750caf47 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -137,9 +137,15 @@ class UPnPDeviceDirectory final : UpnpCallback { Mutex mutex; + /** + * Protected by #mutex. + */ boost::intrusive::list> downloaders; + /** + * Protected by #mutex. + */ std::list directories; /**