Skip to content

Commit

Permalink
[Darwin] MTRDeviceConnectivityMonitor should weakify before using sel…
Browse files Browse the repository at this point in the history
…f in a handler block (project-chip#33395)
  • Loading branch information
jtung-apple authored May 9, 2024
1 parent 2ae320e commit 550b1c1
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/darwin/Framework/CHIP/MTRDeviceConnectivityMonitor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,26 @@ - (void)handleResolvedHostname:(const char *)hostName port:(uint16_t)port error:
return;
}
nw_connection_set_queue(connection, sSharedResolverQueue);
mtr_weakify(self);
nw_connection_set_path_changed_handler(connection, ^(nw_path_t _Nonnull path) {
nw_path_status_t status = nw_path_get_status(path);
if (status == nw_path_status_satisfied) {
MTR_LOG_INFO("%@ path is satisfied", self);
std::lock_guard lock(sConnectivityMonitorLock);
[self _callHandler];
mtr_strongify(self);
if (self) {
nw_path_status_t status = nw_path_get_status(path);
if (status == nw_path_status_satisfied) {
MTR_LOG_INFO("%@ path is satisfied", self);
std::lock_guard lock(sConnectivityMonitorLock);
[self _callHandler];
}
}
});
nw_connection_set_viability_changed_handler(connection, ^(bool viable) {
if (viable) {
std::lock_guard lock(sConnectivityMonitorLock);
MTR_LOG_INFO("%@ connectivity now viable", self);
[self _callHandler];
mtr_strongify(self);
if (self) {
if (viable) {
std::lock_guard lock(sConnectivityMonitorLock);
MTR_LOG_INFO("%@ connectivity now viable", self);
[self _callHandler];
}
}
});
nw_connection_start(connection);
Expand Down

0 comments on commit 550b1c1

Please sign in to comment.