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