Skip to content

Commit 550b1c1

Browse files
authored
[Darwin] MTRDeviceConnectivityMonitor should weakify before using self in a handler block (#33395)
1 parent 2ae320e commit 550b1c1

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/darwin/Framework/CHIP/MTRDeviceConnectivityMonitor.mm

+16-9
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,26 @@ - (void)handleResolvedHostname:(const char *)hostName port:(uint16_t)port error:
148148
return;
149149
}
150150
nw_connection_set_queue(connection, sSharedResolverQueue);
151+
mtr_weakify(self);
151152
nw_connection_set_path_changed_handler(connection, ^(nw_path_t _Nonnull path) {
152-
nw_path_status_t status = nw_path_get_status(path);
153-
if (status == nw_path_status_satisfied) {
154-
MTR_LOG_INFO("%@ path is satisfied", self);
155-
std::lock_guard lock(sConnectivityMonitorLock);
156-
[self _callHandler];
153+
mtr_strongify(self);
154+
if (self) {
155+
nw_path_status_t status = nw_path_get_status(path);
156+
if (status == nw_path_status_satisfied) {
157+
MTR_LOG_INFO("%@ path is satisfied", self);
158+
std::lock_guard lock(sConnectivityMonitorLock);
159+
[self _callHandler];
160+
}
157161
}
158162
});
159163
nw_connection_set_viability_changed_handler(connection, ^(bool viable) {
160-
if (viable) {
161-
std::lock_guard lock(sConnectivityMonitorLock);
162-
MTR_LOG_INFO("%@ connectivity now viable", self);
163-
[self _callHandler];
164+
mtr_strongify(self);
165+
if (self) {
166+
if (viable) {
167+
std::lock_guard lock(sConnectivityMonitorLock);
168+
MTR_LOG_INFO("%@ connectivity now viable", self);
169+
[self _callHandler];
170+
}
164171
}
165172
});
166173
nw_connection_start(connection);

0 commit comments

Comments
 (0)