Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Darwin] MTRDeviceConnectivityMonitor should weakify before using self in a handler block #33395

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading