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

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

Issue 1892623002: Fixes leak of native File objects. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove unused GetFD Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 21 matching lines...) Expand all
32 void set_fd(int fd) { fd_ = fd; } 32 void set_fd(int fd) { fd_ = fd; }
33 33
34 private: 34 private:
35 int fd_; 35 int fd_;
36 36
37 DISALLOW_COPY_AND_ASSIGN(FileHandle); 37 DISALLOW_COPY_AND_ASSIGN(FileHandle);
38 }; 38 };
39 39
40 40
41 File::~File() { 41 File::~File() {
42 Close(); 42 if (!IsClosed()) {
43 Close();
44 }
43 delete handle_; 45 delete handle_;
44 } 46 }
45 47
46 48
47 void File::Close() { 49 void File::Close() {
48 ASSERT(handle_->fd() >= 0); 50 ASSERT(handle_->fd() >= 0);
49 if (handle_->fd() == STDOUT_FILENO) { 51 if (handle_->fd() == STDOUT_FILENO) {
50 // If stdout, redirect fd to /dev/null. 52 // If stdout, redirect fd to /dev/null.
51 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); 53 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY));
52 ASSERT(null_fd >= 0); 54 ASSERT(null_fd >= 0);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 192 }
191 193
192 194
193 File* File::Open(const char* path, FileOpenMode mode) { 195 File* File::Open(const char* path, FileOpenMode mode) {
194 // ScopedOpen doesn't actually need a scope. 196 // ScopedOpen doesn't actually need a scope.
195 return ScopedOpen(path, mode); 197 return ScopedOpen(path, mode);
196 } 198 }
197 199
198 200
199 File* File::OpenStdio(int fd) { 201 File* File::OpenStdio(int fd) {
200 if ((fd < 0) || (2 < fd)) { 202 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd));
201 return NULL;
202 }
203 return new File(new FileHandle(fd));
204 } 203 }
205 204
206 205
207 bool File::Exists(const char* name) { 206 bool File::Exists(const char* name) {
208 struct stat st; 207 struct stat st;
209 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { 208 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) {
210 return S_ISREG(st.st_mode); 209 return S_ISREG(st.st_mode);
211 } else { 210 } else {
212 return false; 211 return false;
213 } 212 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 return ((file_1_info.st_ino == file_2_info.st_ino) && 486 return ((file_1_info.st_ino == file_2_info.st_ino) &&
488 (file_1_info.st_dev == file_2_info.st_dev)) ? 487 (file_1_info.st_dev == file_2_info.st_dev)) ?
489 File::kIdentical : 488 File::kIdentical :
490 File::kDifferent; 489 File::kDifferent;
491 } 490 }
492 491
493 } // namespace bin 492 } // namespace bin
494 } // namespace dart 493 } // namespace dart
495 494
496 #endif // defined(TARGET_OS_ANDROID) 495 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698