Commit 1040b857 authored by Max Kellermann's avatar Max Kellermann

lib/{curl,upnp}: add more exception handlers

Bugs found by Coverity.
parent e2c81aa9
...@@ -72,7 +72,7 @@ CurlRequest::~CurlRequest() noexcept ...@@ -72,7 +72,7 @@ CurlRequest::~CurlRequest() noexcept
} }
void void
CurlRequest::Start() noexcept CurlRequest::Start()
{ {
assert(!registered); assert(!registered);
......
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
* *
* This method must be called in the event loop thread. * This method must be called in the event loop thread.
*/ */
void Start() noexcept; void Start();
/** /**
* Unregister this request via CurlGlobal::Remove(). * Unregister this request via CurlGlobal::Remove().
......
...@@ -174,15 +174,19 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco) noexcept ...@@ -174,15 +174,19 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco) noexcept
{ {
if (isMSDevice(disco->DeviceType) || if (isMSDevice(disco->DeviceType) ||
isCDService(disco->ServiceType)) { isCDService(disco->ServiceType)) {
auto *downloader = new Downloader(*this, *disco);
try { try {
downloader->Start(); auto *downloader = new Downloader(*this, *disco);
} catch (...) {
BlockingCall(GetEventLoop(), [downloader](){ try {
downloader->Destroy(); downloader->Start();
}); } catch (...) {
BlockingCall(GetEventLoop(), [downloader](){
downloader->Destroy();
});
throw;
}
} catch (...) {
LogError(std::current_exception()); LogError(std::current_exception());
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
...@@ -251,7 +255,7 @@ UPnPDeviceDirectory::ExpireDevices() ...@@ -251,7 +255,7 @@ UPnPDeviceDirectory::ExpireDevices()
UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop, UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop,
UpnpClient_Handle _handle, UpnpClient_Handle _handle,
UPnPDiscoveryListener *_listener) noexcept UPnPDiscoveryListener *_listener)
:curl(event_loop), handle(_handle), :curl(event_loop), handle(_handle),
listener(_listener) listener(_listener)
{ {
......
...@@ -110,7 +110,11 @@ class UPnPDeviceDirectory final : UpnpCallback { ...@@ -110,7 +110,11 @@ class UPnPDeviceDirectory final : UpnpCallback {
private: private:
void OnDeferredStart() noexcept { void OnDeferredStart() noexcept {
request.Start(); try {
request.Start();
} catch (...) {
OnError(std::current_exception());
}
} }
/* virtual methods from CurlResponseHandler */ /* virtual methods from CurlResponseHandler */
...@@ -147,7 +151,7 @@ class UPnPDeviceDirectory final : UpnpCallback { ...@@ -147,7 +151,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
public: public:
UPnPDeviceDirectory(EventLoop &event_loop, UpnpClient_Handle _handle, UPnPDeviceDirectory(EventLoop &event_loop, UpnpClient_Handle _handle,
UPnPDiscoveryListener *_listener=nullptr) noexcept; UPnPDiscoveryListener *_listener=nullptr);
~UPnPDeviceDirectory() noexcept; ~UPnPDeviceDirectory() noexcept;
UPnPDeviceDirectory(const UPnPDeviceDirectory &) = delete; UPnPDeviceDirectory(const UPnPDeviceDirectory &) = delete;
......
...@@ -140,7 +140,11 @@ private: ...@@ -140,7 +140,11 @@ private:
void OnDeferredStart() noexcept { void OnDeferredStart() noexcept {
assert(!done); assert(!done);
request.Start(); try {
request.Start();
} catch (...) {
OnError(std::current_exception());
}
} }
/* virtual methods from CurlResponseHandler */ /* virtual methods from CurlResponseHandler */
......
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