From be11de44da14aae7a55809a3d24c027155fed7c0 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Sat, 30 Jan 2016 10:33:41 +1100 Subject: [PATCH] Bug 1241901 part 1 - Remove nsAutoPtr uses in nsNotifyAddrListener on Linux. r=bagder --HG-- extra : source : 5a04cc98fbc2ed3804a130f9adcb7a2a024b4011 --- .../linux/nsNotifyAddrListener_Linux.cpp | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp b/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp index 5696e95ccbc8..b6aace2aabd6 100644 --- a/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp +++ b/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp @@ -18,7 +18,6 @@ #include "nsServiceManagerUtils.h" #include "nsNotifyAddrListener_Linux.h" #include "nsString.h" -#include "nsAutoPtr.h" #include "mozilla/Logging.h" #include "mozilla/Services.h" @@ -158,9 +157,6 @@ void nsNotifyAddrListener::OnNetlinkMessage(int aNetlinkSocket) int attr_len; const struct ifaddrmsg* newifam; - // inspired by check_pf.c. - nsAutoPtr addr; - nsAutoPtr localaddr; ssize_t rc = EINTR_RETRY(recv(aNetlinkSocket, buffer, sizeof(buffer), 0)); if (rc < 0) { @@ -174,6 +170,10 @@ void nsNotifyAddrListener::OnNetlinkMessage(int aNetlinkSocket) for (; NLMSG_OK(nlh, netlink_bytes); nlh = NLMSG_NEXT(nlh, netlink_bytes)) { + char prefixaddr[INET6_ADDRSTRLEN]; + char localaddr[INET6_ADDRSTRLEN]; + char* addr = nullptr; + prefixaddr[0] = localaddr[0] = '\0'; if (NLMSG_DONE == nlh->nlmsg_type) { break; @@ -194,34 +194,31 @@ void nsNotifyAddrListener::OnNetlinkMessage(int aNetlinkSocket) if (attr->rta_type == IFA_ADDRESS) { if (newifam->ifa_family == AF_INET) { struct in_addr* in = (struct in_addr*)RTA_DATA(attr); - addr = new char[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, in, addr.get(), INET_ADDRSTRLEN); + inet_ntop(AF_INET, in, prefixaddr, INET_ADDRSTRLEN); } else { struct in6_addr* in = (struct in6_addr*)RTA_DATA(attr); - addr = new char[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, in, addr.get(), INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, in, prefixaddr, INET6_ADDRSTRLEN); } } else if (attr->rta_type == IFA_LOCAL) { if (newifam->ifa_family == AF_INET) { struct in_addr* in = (struct in_addr*)RTA_DATA(attr); - localaddr = new char[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, in, localaddr.get(), INET_ADDRSTRLEN); + inet_ntop(AF_INET, in, localaddr, INET_ADDRSTRLEN); } else { struct in6_addr* in = (struct in6_addr*)RTA_DATA(attr); - localaddr = new char[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, in, localaddr.get(), INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, in, localaddr, INET6_ADDRSTRLEN); } } } - if (localaddr) { + if (localaddr[0]) { addr = localaddr; - } - if (!addr) { + } else if (prefixaddr[0]) { + addr = prefixaddr; + } else { continue; } if (nlh->nlmsg_type == RTM_NEWADDR) { LOG(("nsNotifyAddrListener::OnNetlinkMessage: a new address " - "- %s.", addr.get())); + "- %s.", addr)); struct ifaddrmsg* ifam; nsCString addrStr; addrStr.Assign(addr); @@ -242,16 +239,12 @@ void nsNotifyAddrListener::OnNetlinkMessage(int aNetlinkSocket) } } else { LOG(("nsNotifyAddrListener::OnNetlinkMessage: an address " - "has been deleted - %s.", addr.get())); + "has been deleted - %s.", addr)); networkChange = true; nsCString addrStr; addrStr.Assign(addr); mAddressInfo.Remove(addrStr); } - - // clean it up. - localaddr = nullptr; - addr = nullptr; } if (networkChange && mAllowChangedEvent) {