Skip to content

Commit 5fcf202

Browse files
author
luoqiangwei1
committed
Fix dumpstate read_file_as_long fd leak
Change-Id: If572b05b662695d007854340db0a6d9fb0a7c60d Signed-off-by: luoqiangwei1 <luoqiangwei1@xiaomi.com>
1 parent f3166e4 commit 5fcf202

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

cmds/dumpstate/dumpstate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,14 +4144,14 @@ int Dumpstate::DumpFile(const std::string& title, const std::string& path) {
41444144
}
41454145

41464146
int read_file_as_long(const char *path, long int *output) {
4147-
int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC));
4148-
if (fd < 0) {
4147+
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC)));
4148+
if (fd.get() < 0) {
41494149
int err = errno;
41504150
MYLOGE("Error opening file descriptor for %s: %s\n", path, strerror(err));
41514151
return -1;
41524152
}
41534153
char buffer[50];
4154-
ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, sizeof(buffer)));
4154+
ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd.get(), buffer, sizeof(buffer)));
41554155
if (bytes_read == -1) {
41564156
MYLOGE("Error reading file %s: %s\n", path, strerror(errno));
41574157
return -2;

0 commit comments

Comments
 (0)