summaryrefslogtreecommitdiff
path: root/cmds/dumpstate/dumpstate.cpp
diff options
context:
space:
mode:
author luoqiangwei1 <luoqiangwei1@xiaomi.com> 2024-03-07 15:29:20 +0800
committer luoqiangwei1 <luoqiangwei1@xiaomi.com> 2024-03-07 15:29:51 +0800
commit5fcf202313c44278914adf61258bb7f9d17e40ba (patch)
treed616fbe906406926931d853d29e6bc35cd6b2fe5 /cmds/dumpstate/dumpstate.cpp
parentf3166e46ed71396cd876c1baae3d3c5a35f005bc (diff)
Fix dumpstate read_file_as_long fd leak
Change-Id: If572b05b662695d007854340db0a6d9fb0a7c60d Signed-off-by: luoqiangwei1 <luoqiangwei1@xiaomi.com>
Diffstat (limited to 'cmds/dumpstate/dumpstate.cpp')
-rw-r--r--cmds/dumpstate/dumpstate.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 326f927862..6d155aa9c3 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -4144,14 +4144,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;