Skip to content

Commit df17b83

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Fix dumpstate read_file_as_long fd leak" into main
2 parents 790bbb9 + 5fcf202 commit df17b83

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
@@ -4143,14 +4143,14 @@ int Dumpstate::DumpFile(const std::string& title, const std::string& path) {
41434143
}
41444144

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

0 commit comments

Comments
 (0)