Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a568e530 authored by Josh Gao's avatar Josh Gao
Browse files

Fix leaks in wifi_chip.cpp.

Use closedir on DIR*, instead of close(dirfd(DIR*)).

Bug: http://b/109702699
Test: mma
Change-Id: I827d3a414761bb836d5360221296823fcb34cd6b
parent 25ae1956
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -111,16 +111,16 @@ std::string getP2pIfaceName() {
bool removeOldFilesInternal() {
    time_t now = time(0);
    const time_t delete_files_before = now - kMaxRingBufferFileAgeSeconds;
    DIR* dir_dump = opendir(kTombstoneFolderPath);
    std::unique_ptr<DIR, decltype(&closedir)> dir_dump(
        opendir(kTombstoneFolderPath), closedir);
    if (!dir_dump) {
        LOG(ERROR) << "Failed to open directory: " << strerror(errno);
        return false;
    }
    unique_fd dir_auto_closer(dirfd(dir_dump));
    struct dirent* dp;
    bool success = true;
    std::list<std::pair<const time_t, std::string>> valid_files;
    while ((dp = readdir(dir_dump))) {
    while ((dp = readdir(dir_dump.get()))) {
        if (dp->d_type != DT_REG) {
            continue;
        }
@@ -246,13 +246,13 @@ bool cpioWriteFileTrailer(int out_fd) {
size_t cpioArchiveFilesInDir(int out_fd, const char* input_dir) {
    struct dirent* dp;
    size_t n_error = 0;
    DIR* dir_dump = opendir(input_dir);
    std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(input_dir),
                                                       closedir);
    if (!dir_dump) {
        LOG(ERROR) << "Failed to open directory: " << strerror(errno);
        return ++n_error;
    }
    unique_fd dir_auto_closer(dirfd(dir_dump));
    while ((dp = readdir(dir_dump))) {
    while ((dp = readdir(dir_dump.get()))) {
        if (dp->d_type != DT_REG) {
            continue;
        }