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

Side by Side Diff: runtime/bin/socket_macos.cc

Issue 1781883002: Fixes some memory leaks in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix tests on Windows Created 4 years, 9 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 | « runtime/bin/socket_linux.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "bin/socket.h"
9 #include "bin/socket_macos.h"
10
8 #include <errno.h> // NOLINT 11 #include <errno.h> // NOLINT
9 #include <stdio.h> // NOLINT 12 #include <stdio.h> // NOLINT
10 #include <stdlib.h> // NOLINT 13 #include <stdlib.h> // NOLINT
11 #include <string.h> // NOLINT 14 #include <string.h> // NOLINT
12 #include <sys/stat.h> // NOLINT 15 #include <sys/stat.h> // NOLINT
13 #include <unistd.h> // NOLINT 16 #include <unistd.h> // NOLINT
14 #include <net/if.h> // NOLINT 17 #include <net/if.h> // NOLINT
15 #include <netinet/tcp.h> // NOLINT 18 #include <netinet/tcp.h> // NOLINT
16 #include <ifaddrs.h> // NOLINT 19 #include <ifaddrs.h> // NOLINT
17 20
18 #include "bin/fdutils.h" 21 #include "bin/fdutils.h"
19 #include "bin/file.h" 22 #include "bin/file.h"
20 #include "bin/socket.h"
21
22 #include "platform/signal_blocker.h" 23 #include "platform/signal_blocker.h"
23 24
24
25 namespace dart { 25 namespace dart {
26 namespace bin { 26 namespace bin {
27 27
28 SocketAddress::SocketAddress(struct sockaddr* sa) { 28 SocketAddress::SocketAddress(struct sockaddr* sa) {
29 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); 29 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
30 if (!Socket::FormatNumericAddress( 30 if (!Socket::FormatNumericAddress(
31 *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { 31 *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) {
32 as_string_[0] = 0; 32 as_string_[0] = 0;
33 } 33 }
34 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); 34 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa));
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 intptr_t count = 0; 352 intptr_t count = 0;
353 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { 353 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
354 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) count++; 354 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) count++;
355 } 355 }
356 356
357 AddressList<InterfaceSocketAddress>* addresses = 357 AddressList<InterfaceSocketAddress>* addresses =
358 new AddressList<InterfaceSocketAddress>(count); 358 new AddressList<InterfaceSocketAddress>(count);
359 int i = 0; 359 int i = 0;
360 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { 360 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
361 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) { 361 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) {
362 char* ifa_name = DartUtils::ScopedCopyCString(ifa->ifa_name);
362 addresses->SetAt(i, new InterfaceSocketAddress( 363 addresses->SetAt(i, new InterfaceSocketAddress(
363 ifa->ifa_addr, strdup(ifa->ifa_name), if_nametoindex(ifa->ifa_name))); 364 ifa->ifa_addr, ifa_name, if_nametoindex(ifa->ifa_name)));
364 i++; 365 i++;
365 } 366 }
366 } 367 }
367 freeifaddrs(ifaddr); 368 freeifaddrs(ifaddr);
368 return addresses; 369 return addresses;
369 } 370 }
370 371
371 372
372 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, 373 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
373 intptr_t backlog, 374 intptr_t backlog,
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 const RawAddr& addr, 612 const RawAddr& addr,
612 const RawAddr& interface, 613 const RawAddr& interface,
613 int interfaceIndex) { 614 int interfaceIndex) {
614 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); 615 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false);
615 } 616 }
616 617
617 } // namespace bin 618 } // namespace bin
618 } // namespace dart 619 } // namespace dart
619 620
620 #endif // defined(TARGET_OS_MACOS) 621 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/socket_linux.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698