diff options
author | Calin Juravle <calin@google.com> | 2014-06-03 16:30:39 +0100 |
---|---|---|
committer | Calin Juravle <calin@google.com> | 2014-06-04 11:37:30 +0100 |
commit | 177b429a54a57adbe922037b1210e596d8348d2a (patch) | |
tree | 252bffe6c276fa528b0f66d471d726aa94f3552f /runtime/native | |
parent | e4283be97047a26d3476acd3863dcc386498be17 (diff) | |
download | art-177b429a54a57adbe922037b1210e596d8348d2a.zip art-177b429a54a57adbe922037b1210e596d8348d2a.tar.gz art-177b429a54a57adbe922037b1210e596d8348d2a.tar.bz2 |
Fix a possible file descriptor leakage
Bug: 15279918
Change-Id: I7909a53f9028d2f445fb97a0a4293f36b3c012dd
Diffstat (limited to 'runtime/native')
-rw-r--r-- | runtime/native/dalvik_system_DexFile.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc index a0a294a..8588c3a 100644 --- a/runtime/native/dalvik_system_DexFile.cc +++ b/runtime/native/dalvik_system_DexFile.cc @@ -35,6 +35,7 @@ #include "profiler.h" #include "runtime.h" #include "scoped_thread_state_change.h" +#include "ScopedFd.h" #include "ScopedLocalRef.h" #include "ScopedUtfChars.h" #include "well_known_classes.h" @@ -220,8 +221,8 @@ static jobjectArray DexFile_getClassNameList(JNIEnv* env, jclass, jlong cookie) // Copy a profile file static void CopyProfileFile(const char* oldfile, const char* newfile) { - int fd = open(oldfile, O_RDONLY); - if (fd < 0) { + ScopedFd fd(open(oldfile, O_RDONLY)); + if (fd.get() == -1) { // If we can't open the file show the uid:gid of the this process to allow // diagnosis of the problem. LOG(ERROR) << "Failed to open profile file " << oldfile<< ". My uid:gid is " @@ -230,8 +231,8 @@ static void CopyProfileFile(const char* oldfile, const char* newfile) { } // Create the copy with rw------- (only accessible by system) - int fd2 = open(newfile, O_WRONLY|O_CREAT|O_TRUNC, 0600); - if (fd2 < 0) { + ScopedFd fd2(open(newfile, O_WRONLY|O_CREAT|O_TRUNC, 0600)); + if (fd2.get() == -1) { // If we can't open the file show the uid:gid of the this process to allow // diagnosis of the problem. LOG(ERROR) << "Failed to create/write prev profile file " << newfile << ". My uid:gid is " @@ -240,14 +241,12 @@ static void CopyProfileFile(const char* oldfile, const char* newfile) { } char buf[4096]; while (true) { - int n = read(fd, buf, sizeof(buf)); + int n = read(fd.get(), buf, sizeof(buf)); if (n <= 0) { break; } - write(fd2, buf, n); + write(fd2.get(), buf, n); } - close(fd); - close(fd2); } static double GetDoubleProperty(const char* property, double minValue, double maxValue, double defaultValue) { |