From 1ea631f4a769305a372cfb8fcf455c10f8f0a8aa Mon Sep 17 00:00:00 2001 From: oprypin Date: Fri, 18 Aug 2017 00:15:19 -0700 Subject: [PATCH] Fix a delete type mismatch (deleting a sockaddr_in6* as a sockaddr*) This triggered ASan, saying "object passed to delete has wrong type". This error is caused by allocating a `struct sockaddr_in6`, casting it and deleting it as `struct sockaddr*` which has a smaller size. BUG=None Review-Url: https://codereview.webrtc.org/2999053002 Cr-Commit-Position: refs/heads/master@{#19401} --- webrtc/rtc_base/network_unittest.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webrtc/rtc_base/network_unittest.cc b/webrtc/rtc_base/network_unittest.cc index b5c5912aa..9af9294c6 100644 --- a/webrtc/rtc_base/network_unittest.cc +++ b/webrtc/rtc_base/network_unittest.cc @@ -10,8 +10,11 @@ #include "webrtc/rtc_base/network.h" +#include + #include #include + #include "webrtc/rtc_base/checks.h" #include "webrtc/rtc_base/nethelpers.h" #include "webrtc/rtc_base/networkmonitor.h" @@ -122,7 +125,8 @@ class NetworkTest : public testing::Test, public sigslot::has_slots<> { struct sockaddr_in6* CreateIpv6Addr(const std::string& ip_string, uint32_t scope_id) { - struct sockaddr_in6* ipv6_addr = new struct sockaddr_in6; + struct sockaddr_in6* ipv6_addr = static_cast( + malloc(sizeof(struct sockaddr_in6))); memset(ipv6_addr, 0, sizeof(struct sockaddr_in6)); ipv6_addr->sin6_family = AF_INET6; ipv6_addr->sin6_scope_id = scope_id; @@ -168,8 +172,8 @@ class NetworkTest : public testing::Test, public sigslot::has_slots<> { struct ifaddrs* if_addr = list; while (if_addr != nullptr) { struct ifaddrs* next_addr = if_addr->ifa_next; - delete if_addr->ifa_addr; - delete if_addr->ifa_netmask; + free(if_addr->ifa_addr); + free(if_addr->ifa_netmask); delete if_addr; if_addr = next_addr; }