[ObjC] Avoid usage of variable after move in RTCNetworkMonitor.

Allocate std::map in-place and capture pointer to it by Obj-C
lambda.

Bug: None
Change-Id: I285d8b2d10fef9130a5d0e457ad3982ff8a1f00f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/375920
Commit-Queue: Yury Yarashevich <yura.yaroshevich@gmail.com>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43840}
This commit is contained in:
Yury Yarashevich 2025-02-03 12:01:36 +01:00 committed by WebRTC LUCI CQ
parent f80562d22a
commit ae24807590

View File

@ -82,30 +82,24 @@ rtc::AdapterType AdapterTypeFromInterfaceType(
} else if (status == nw_path_status_satisfiable) { } else if (status == nw_path_status_satisfiable) {
RTCLog(@"NW path monitor status: satisfiable."); RTCLog(@"NW path monitor status: satisfiable.");
} }
std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp> *map = std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>
new std:: owned_map;
map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp>(); auto map = &owned_map; // Capture raw pointer for Objective-C block
nw_path_enumerate_interfaces( nw_path_enumerate_interfaces(path, ^(nw_interface_t interface) {
path, const char *name = nw_interface_get_name(interface);
(nw_path_enumerate_interfaces_block_t) ^ nw_interface_type_t interfaceType = nw_interface_get_type(interface);
(nw_interface_t interface) { RTCLog(@"NW path monitor available interface: %s", name);
const char *name = nw_interface_get_name(interface); rtc::AdapterType adapterType =
nw_interface_type_t interfaceType = AdapterTypeFromInterfaceType(interfaceType);
nw_interface_get_type(interface); map->emplace(name, adapterType);
RTCLog(@"NW path monitor available interface: %s", name); return true;
rtc::AdapterType adapterType = });
AdapterTypeFromInterfaceType(interfaceType);
map->insert(std::pair<std::string, rtc::AdapterType>(
name, adapterType));
return true;
});
@synchronized(strongSelf) { @synchronized(strongSelf) {
webrtc::NetworkMonitorObserver *observer = strongSelf->_observer; webrtc::NetworkMonitorObserver *observer = strongSelf->_observer;
if (observer) { if (observer) {
observer->OnPathUpdate(std::move(*map)); observer->OnPathUpdate(std::move(owned_map));
} }
} }
delete map;
}); });
nw_path_monitor_set_queue( nw_path_monitor_set_queue(
_pathMonitor, _pathMonitor,