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

Commit 5522a0eb authored by yipeng xiang's avatar yipeng xiang Committed by Dipankar Bhardwaj
Browse files

Fix

FileObserver memory leak, If an application use FileObserver funtion startWatching some files, then stopWatching, WeakReference will leak in mRealObservers container.

Bug: 379797597
(cherry picked from https://android-review.googlesource.com/q/commit:c004cd180c8fb8aa60bd512877915f4a72c49569)
Merged-In: Ibbcae08c1d38f7b8a8e295368e251c3b074d461c
Change-Id: Ibbcae08c1d38f7b8a8e295368e251c3b074d461c
Flag: EXEMPT bug fix
parent ab5f8b23
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ public abstract class FileObserver {
    private static class ObserverThread extends Thread {
        /** Temporarily retained; appears to be missing UnsupportedAppUsage annotation */
        private HashMap<Integer, WeakReference> m_observers = new HashMap<Integer, WeakReference>();
        private SparseArray<WeakReference> mRealObservers = new SparseArray<>();
        private final SparseArray<WeakReference> mRealObservers = new SparseArray<>();
        private int m_fd;

        public ObserverThread() {
@@ -143,6 +143,11 @@ public abstract class FileObserver {

        public void stopWatching(int[] descriptors) {
            stopWatching(m_fd, descriptors);
            synchronized (mRealObservers) {
                for (int wfd: descriptors) {
                    mRealObservers.delete(wfd);
                }
            }
        }

        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)