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

Commit f25cad29 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Make openWrite more resilient.

Before this change, mMainOutStream is not null, but any of subsequent 'new'-s fails then failWrite will also fail, crashing the system_server.

Bug: 286046288
Fixes: 286046288
Test: presubmit
Change-Id: I2e7159e8944f75a38a676c3f71da3b6933cf0b2a
parent 984eafe8
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -107,10 +107,15 @@ final class ResilientAtomicFile implements Closeable {

        // In case of MT access, it's possible the files get overwritten during write.
        // Let's open all FDs we need now.
        try {
            mMainOutStream = new FileOutputStream(mFile);
            mMainInStream = new FileInputStream(mFile);
            mReserveOutStream = new FileOutputStream(mReserveCopy);
            mReserveInStream = new FileInputStream(mReserveCopy);
        } catch (IOException e) {
            close();
            throw e;
        }

        return mMainOutStream;
    }