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

Side by Side Diff: runtime/bin/socket_linux.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_android.cc ('k') | runtime/bin/socket_macos.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_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/socket.h"
9 #include "bin/socket_linux.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 #include "bin/thread.h" 23 #include "bin/thread.h"
22 #include "platform/signal_blocker.h" 24 #include "platform/signal_blocker.h"
23 25
24
25 namespace dart { 26 namespace dart {
26 namespace bin { 27 namespace bin {
27 28
28 SocketAddress::SocketAddress(struct sockaddr* sa) { 29 SocketAddress::SocketAddress(struct sockaddr* sa) {
29 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); 30 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
30 if (!Socket::FormatNumericAddress( 31 if (!Socket::FormatNumericAddress(
31 *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { 32 *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) {
32 as_string_[0] = 0; 33 as_string_[0] = 0;
33 } 34 }
34 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); 35 socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa));
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 intptr_t count = 0; 349 intptr_t count = 0;
349 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { 350 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
350 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) count++; 351 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) count++;
351 } 352 }
352 353
353 AddressList<InterfaceSocketAddress>* addresses = 354 AddressList<InterfaceSocketAddress>* addresses =
354 new AddressList<InterfaceSocketAddress>(count); 355 new AddressList<InterfaceSocketAddress>(count);
355 int i = 0; 356 int i = 0;
356 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { 357 for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
357 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) { 358 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) {
359 char* ifa_name = DartUtils::ScopedCopyCString(ifa->ifa_name);
358 addresses->SetAt(i, new InterfaceSocketAddress( 360 addresses->SetAt(i, new InterfaceSocketAddress(
359 ifa->ifa_addr, strdup(ifa->ifa_name), if_nametoindex(ifa->ifa_name))); 361 ifa->ifa_addr, ifa_name, if_nametoindex(ifa->ifa_name)));
360 i++; 362 i++;
361 } 363 }
362 } 364 }
363 freeifaddrs(ifaddr); 365 freeifaddrs(ifaddr);
364 return addresses; 366 return addresses;
365 } 367 }
366 368
367 369
368 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, 370 intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
369 intptr_t backlog, 371 intptr_t backlog,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 mreq.gr_interface = interfaceIndex; 567 mreq.gr_interface = interfaceIndex;
566 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); 568 memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr));
567 return NO_RETRY_EXPECTED( 569 return NO_RETRY_EXPECTED(
568 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; 570 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
569 } 571 }
570 572
571 } // namespace bin 573 } // namespace bin
572 } // namespace dart 574 } // namespace dart
573 575
574 #endif // defined(TARGET_OS_LINUX) 576 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698