diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 80157c707..f6a3ba122 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -212,7 +212,6 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp) bool UPnPDeviceDirectory::ExpireDevices(Error &error) { - const ScopeLock protect(mutex); const unsigned now = MonotonicClockS(); bool didsomething = false; @@ -291,12 +290,11 @@ bool UPnPDeviceDirectory::GetDirectories(std::vector &out, Error &error) { - // Has locking, do it before our own lock + const ScopeLock protect(mutex); + if (!ExpireDevices(error)) return false; - const ScopeLock protect(mutex); - for (auto dit = directories.begin(); dit != directories.end(); dit++) { for (const auto &service : dit->device.services) { @@ -314,12 +312,11 @@ UPnPDeviceDirectory::GetServer(const char *friendly_name, ContentDirectoryService &server, Error &error) { - // Has locking, do it before our own lock + const ScopeLock protect(mutex); + if (!ExpireDevices(error)) return false; - const ScopeLock protect(mutex); - for (const auto &i : directories) { const auto &device = i.device; diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 970fb306e..1cf82b77e 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -138,6 +138,8 @@ private: * Look at the devices and get rid of those which have not * been seen for too long. We do this when listing the top * directory. + * + * Caller must lock #mutex. */ bool ExpireDevices(Error &error);