natpmp: avoid to post after context shutdown
Else, a deadlock may occurs
https://git.jami.net/savoirfairelinux/jami-daemon/-/issues/936
Change-Id: Ib4a02845bd0b7e5d482f3fc5f5c8b8a01a50a80f
diff --git a/src/upnp/protocol/natpmp/nat_pmp.cpp b/src/upnp/protocol/natpmp/nat_pmp.cpp
index 48e010a..7e88ad7 100644
--- a/src/upnp/protocol/natpmp/nat_pmp.cpp
+++ b/src/upnp/protocol/natpmp/nat_pmp.cpp
@@ -676,7 +676,13 @@
if (observer_ == nullptr)
return;
// Process the response on the context thread.
- ioContext->post([obs = observer_, igd = igd_, event] { obs->onIgdUpdated(igd, event); });
+ ioContext->post([w = weak(), event] {
+ if (auto shared = w.lock()) {
+ if (!shared->shutdownComplete_) {
+ shared->observer_->onIgdUpdated(shared->igd_, event);
+ }
+ }
+ });
}
void
@@ -686,7 +692,13 @@
return;
// Process the response on the context thread.
- ioContext->post([obs = observer_, igd = igd_, map] { obs->onMappingAdded(igd, map); });
+ ioContext->post([w=weak(), map] {
+ if (auto shared = w.lock()) {
+ if (!shared->shutdownComplete_) {
+ shared->observer_->onMappingAdded(shared->igd_, map);
+ }
+ }
+ });
}
void
@@ -696,7 +708,13 @@
return;
// Process the response on the context thread.
- ioContext->post([obs = observer_, igd = igd_, map] { obs->onMappingRequestFailed(map); });
+ ioContext->post([w=weak(), map] {
+ if (auto shared = w.lock()) {
+ if (!shared->shutdownComplete_) {
+ shared->observer_->onMappingRequestFailed(map);
+ }
+ }
+ });
}
void
@@ -706,7 +724,13 @@
return;
// Process the response on the context thread.
- ioContext->post([obs = observer_, igd = igd_, map] { obs->onMappingRenewed(igd, map); });
+ ioContext->post([w=weak(), map] {
+ if (auto shared = w.lock()) {
+ if (!shared->shutdownComplete_) {
+ shared->observer_->onMappingRenewed(shared->igd_, map);
+ }
+ }
+ });
}
void
@@ -716,7 +740,13 @@
return;
// Process the response on the context thread.
- ioContext->post([obs = observer_, igd = igd_, map] { obs->onMappingRemoved(igd, map); });
+ ioContext->post([w=weak(), map] {
+ if (auto shared = w.lock()) {
+ if (!shared->shutdownComplete_) {
+ shared->observer_->onMappingRemoved(shared->igd_, map);
+ }
+ }
+ });
}
} // namespace upnp