diff options
author | 2024-03-11 10:17:42 +0000 | |
---|---|---|
committer | 2024-03-11 10:17:42 +0000 | |
commit | df17b83ccfa52c58a3821703ee6a26dce2adc369 (patch) | |
tree | df94385787f4603d3637cbfe9123fd02b3d47225 /cmds/dumpstate/dumpstate.cpp | |
parent | 790bbb927638b103434c5cc456b0bd345607905b (diff) | |
parent | 5fcf202313c44278914adf61258bb7f9d17e40ba (diff) |
Merge "Fix dumpstate read_file_as_long fd leak" into main
Diffstat (limited to 'cmds/dumpstate/dumpstate.cpp')
-rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index befb5d4b5b..c501921399 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -4143,14 +4143,14 @@ int Dumpstate::DumpFile(const std::string& title, const std::string& path) { } int read_file_as_long(const char *path, long int *output) { - int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC)); - if (fd < 0) { + android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC))); + if (fd.get() < 0) { int err = errno; MYLOGE("Error opening file descriptor for %s: %s\n", path, strerror(err)); return -1; } char buffer[50]; - ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, sizeof(buffer))); + ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd.get(), buffer, sizeof(buffer))); if (bytes_read == -1) { MYLOGE("Error reading file %s: %s\n", path, strerror(errno)); return -2; |