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

Commit ab40ab67 authored by Jeffrey Huang's avatar Jeffrey Huang
Browse files

Close the FD after opening the file

Bug: 183758470
Test: Manually took incident report and verified the file is deleted
Change-Id: I040306c2365bcf98efde94fcc15575c9131f3b0e
parent 3bf5cbb8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -400,6 +400,7 @@ status_t ReportFile::startFilteringData(int writeFd, const IncidentReportArgs& a
    if (dataFd < 0) {
        ALOGW("Error opening incident report '%s' %s", getDataFileName().c_str(), strerror(-errno));
        close(writeFd);
        close(dataFd);
        return -errno;
    }

@@ -409,6 +410,7 @@ status_t ReportFile::startFilteringData(int writeFd, const IncidentReportArgs& a
        ALOGW("Error running fstat incident report '%s' %s", getDataFileName().c_str(),
              strerror(-errno));
        close(writeFd);
        close(dataFd);
        return -errno;
    }
    if (st.st_size != mEnvelope.data_file_size()) {
@@ -418,6 +420,7 @@ status_t ReportFile::startFilteringData(int writeFd, const IncidentReportArgs& a
        ALOGW("Removing incident report");
        mWorkDirectory->remove(this);
        close(writeFd);
        close(dataFd);
        return BAD_VALUE;
    }

@@ -427,11 +430,13 @@ status_t ReportFile::startFilteringData(int writeFd, const IncidentReportArgs& a
        if (!zipPipe.init()) {
            ALOGE("[ReportFile] Failed to setup pipe for gzip");
            close(writeFd);
            close(dataFd);
            return -errno;
        }
        int status = 0;
        zipPid = fork_execute_cmd((char* const*)GZIP, zipPipe.readFd().release(), writeFd, &status);
        close(writeFd);
        close(dataFd);
        if (zipPid < 0 || status != 0) {
            ALOGE("[ReportFile] Failed to fork and exec gzip");
            return status;
@@ -459,6 +464,7 @@ status_t ReportFile::startFilteringData(int writeFd, const IncidentReportArgs& a
    }

    close(writeFd);
    close(dataFd);
    if (zipPid > 0) {
        status_t err = wait_child(zipPid, /* timeout_ms= */ 10 * 1000);
        if (err != 0) {