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

Commit 35896935 authored by lijilou's avatar lijilou
Browse files

PowerStatsLogger: ensure the opend stream is closed when IOException happen.

Bug: none
Flag: EXEMPT minor optimization
Change-Id: Ic035870b886ac13a6c8c38ad484eec2840cc3165
parent 2daef7f6
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -285,14 +285,20 @@ public final class PowerStatsLogger extends Handler {
    }

    private void updateCacheFile(String cacheFilename, byte[] data) {
        AtomicFile atomicCachedFile = null;
        FileOutputStream fos = null;
        try {
            final AtomicFile atomicCachedFile =
            atomicCachedFile =
                    new AtomicFile(new File(mDataStoragePath, cacheFilename));
            final FileOutputStream fos = atomicCachedFile.startWrite();
            fos = atomicCachedFile.startWrite();
            fos.write(data);
            atomicCachedFile.finishWrite(fos);
        } catch (IOException e) {
            Slog.e(TAG, "Failed to write current data to cached file", e);
            if (fos != null) {
                atomicCachedFile.failWrite(fos);
            }
            return;
        }
    }