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

Commit 7f20b0d1 authored by John Reck's avatar John Reck Committed by Josh Gao
Browse files

Fix regression in PFD#fromData

Don't rely on the GC to clean up FD resources when they can
just be cleaned up immediately. We know the MemoryFile isn't
going to be used any further, so just close it.

Bug: 138323667
Test: none
Change-Id: Ic82006c9cb48f580aaad942c4679e774186382c9
Merged-In: Ic82006c9cb48f580aaad942c4679e774186382c9
(cherry-picked from commit d201b44032cdd86177406051dcc07f4625ed3b69)
parent aaab62e3
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -584,12 +584,16 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
    public static ParcelFileDescriptor fromData(byte[] data, String name) throws IOException {
        if (data == null) return null;
        MemoryFile file = new MemoryFile(name, data.length);
        try {
            if (data.length > 0) {
                file.writeBytes(data, 0, 0, data.length);
            }
            file.deactivate();
            FileDescriptor fd = file.getFileDescriptor();
            return fd != null ? ParcelFileDescriptor.dup(fd) : null;
        } finally {
            file.close();
        }
    }

    /**