Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: webrtc/rtc_base/network_unittest.cc

Issue 2999053002: Fix a delete type mismatch (deleting a sockaddr_in6* as a sockaddr*) (Closed)
Patch Set: Rework to use malloc/free Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/rtc_base/network.h" 11 #include "webrtc/rtc_base/network.h"
12 12
13 #include <stdlib.h>
14
13 #include <memory> 15 #include <memory>
14 #include <vector> 16 #include <vector>
17
15 #include "webrtc/rtc_base/checks.h" 18 #include "webrtc/rtc_base/checks.h"
16 #include "webrtc/rtc_base/nethelpers.h" 19 #include "webrtc/rtc_base/nethelpers.h"
17 #include "webrtc/rtc_base/networkmonitor.h" 20 #include "webrtc/rtc_base/networkmonitor.h"
18 #if defined(WEBRTC_POSIX) 21 #if defined(WEBRTC_POSIX)
19 #include <sys/types.h> 22 #include <sys/types.h>
20 #include <net/if.h> 23 #include <net/if.h>
21 #include "webrtc/rtc_base/ifaddrs_converter.h" 24 #include "webrtc/rtc_base/ifaddrs_converter.h"
22 #endif // defined(WEBRTC_POSIX) 25 #endif // defined(WEBRTC_POSIX)
23 #include "webrtc/rtc_base/gunit.h" 26 #include "webrtc/rtc_base/gunit.h"
24 #if defined(WEBRTC_WIN) 27 #if defined(WEBRTC_WIN)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 bool include_ignored, 118 bool include_ignored,
116 NetworkManager::NetworkList* networks) { 119 NetworkManager::NetworkList* networks) {
117 // Use the base IfAddrsConverter for test cases. 120 // Use the base IfAddrsConverter for test cases.
118 std::unique_ptr<IfAddrsConverter> ifaddrs_converter(new IfAddrsConverter()); 121 std::unique_ptr<IfAddrsConverter> ifaddrs_converter(new IfAddrsConverter());
119 network_manager.ConvertIfAddrs(interfaces, ifaddrs_converter.get(), 122 network_manager.ConvertIfAddrs(interfaces, ifaddrs_converter.get(),
120 include_ignored, networks); 123 include_ignored, networks);
121 } 124 }
122 125
123 struct sockaddr_in6* CreateIpv6Addr(const std::string& ip_string, 126 struct sockaddr_in6* CreateIpv6Addr(const std::string& ip_string,
124 uint32_t scope_id) { 127 uint32_t scope_id) {
125 struct sockaddr_in6* ipv6_addr = new struct sockaddr_in6; 128 struct sockaddr_in6* ipv6_addr = static_cast<struct sockaddr_in6*>(
129 malloc(sizeof(struct sockaddr_in6)));
kwiberg-webrtc 2017/08/17 22:18:48 Note: Unlike in C, in C++ you don't have to say "s
oprypin_webrtc 2017/08/18 07:12:37 Leaving as is because these pure C structs are ref
126 memset(ipv6_addr, 0, sizeof(struct sockaddr_in6)); 130 memset(ipv6_addr, 0, sizeof(struct sockaddr_in6));
kwiberg-webrtc 2017/08/17 22:18:48 You could replace the malloc+memset pair with call
oprypin_webrtc 2017/08/18 07:12:37 I did give `calloc` a fair consideration, but it's
127 ipv6_addr->sin6_family = AF_INET6; 131 ipv6_addr->sin6_family = AF_INET6;
128 ipv6_addr->sin6_scope_id = scope_id; 132 ipv6_addr->sin6_scope_id = scope_id;
129 IPAddress ip; 133 IPAddress ip;
130 IPFromString(ip_string, &ip); 134 IPFromString(ip_string, &ip);
131 ipv6_addr->sin6_addr = ip.ipv6_address(); 135 ipv6_addr->sin6_addr = ip.ipv6_address();
132 return ipv6_addr; 136 return ipv6_addr;
133 } 137 }
134 138
135 // Pointers created here need to be released via ReleaseIfAddrs. 139 // Pointers created here need to be released via ReleaseIfAddrs.
136 struct ifaddrs* AddIpv6Address(struct ifaddrs* list, 140 struct ifaddrs* AddIpv6Address(struct ifaddrs* list,
(...skipping 24 matching lines...) Expand all
161 NetworkManager::Stats stats; 165 NetworkManager::Stats stats;
162 CallConvertIfAddrs(network_manager, addr_list, true, &result); 166 CallConvertIfAddrs(network_manager, addr_list, true, &result);
163 network_manager.MergeNetworkList(result, &changed, &stats); 167 network_manager.MergeNetworkList(result, &changed, &stats);
164 return addr_list; 168 return addr_list;
165 } 169 }
166 170
167 void ReleaseIfAddrs(struct ifaddrs* list) { 171 void ReleaseIfAddrs(struct ifaddrs* list) {
168 struct ifaddrs* if_addr = list; 172 struct ifaddrs* if_addr = list;
169 while (if_addr != nullptr) { 173 while (if_addr != nullptr) {
170 struct ifaddrs* next_addr = if_addr->ifa_next; 174 struct ifaddrs* next_addr = if_addr->ifa_next;
171 delete if_addr->ifa_addr; 175 free(if_addr->ifa_addr);
172 delete if_addr->ifa_netmask; 176 free(if_addr->ifa_netmask);
173 delete if_addr; 177 delete if_addr;
174 if_addr = next_addr; 178 if_addr = next_addr;
175 } 179 }
176 } 180 }
177 #endif // defined(WEBRTC_POSIX) 181 #endif // defined(WEBRTC_POSIX)
178 182
179 protected: 183 protected:
180 bool callback_called_; 184 bool callback_called_;
181 }; 185 };
182 186
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 // If the set default address is in a network, GetDefaultLocalAddress will 1140 // If the set default address is in a network, GetDefaultLocalAddress will
1137 // return the best IP in that network. 1141 // return the best IP in that network.
1138 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip2); 1142 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip2);
1139 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); 1143 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip));
1140 EXPECT_EQ(static_cast<IPAddress>(ip1), ip); 1144 EXPECT_EQ(static_cast<IPAddress>(ip1), ip);
1141 1145
1142 manager.StopUpdating(); 1146 manager.StopUpdating();
1143 } 1147 }
1144 1148
1145 } // namespace rtc 1149 } // namespace rtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698