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

Commit 14f83cb1 authored by Song Chun Fan's avatar Song Chun Fan Committed by Android (Google) Code Review
Browse files

Merge "[SettingsProvider] fix potential MemoryIntArray leakage" into main

parents a2fa8d88 5991c48a
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -3176,15 +3176,7 @@ public final class Settings {
        }
        public void destroy() {
            try {
                // If this process is the system server process, mArray is the same object as
                // the memory int array kept inside SettingsProvider, so skipping the close()
                if (!Settings.isInSystemServer() && !mArray.isClosed()) {
                    mArray.close();
                }
            } catch (IOException e) {
                Log.e(TAG, "Error closing backing array", e);
            }
            maybeCloseGenerationArray(mArray);
        }
        @Override
@@ -3197,6 +3189,21 @@ public final class Settings {
        }
    }
    private static void maybeCloseGenerationArray(@Nullable MemoryIntArray array) {
        if (array == null) {
            return;
        }
        try {
            // If this process is the system server process, the MemoryIntArray received from Parcel
            // is the same object as the one kept inside SettingsProvider, so skipping the close().
            if (!Settings.isInSystemServer() && !array.isClosed()) {
                array.close();
            }
        } catch (IOException e) {
            Log.e(TAG, "Error closing the generation tracking array", e);
        }
    }
    private static final class ContentProviderHolder {
        private final Object mLock = new Object();
@@ -3504,6 +3511,8 @@ public final class Settings {
                                        mGenerationTrackers.put(name, new GenerationTracker(name,
                                                array, index, generation,
                                                mGenerationTrackerErrorHandler));
                                    } else {
                                        maybeCloseGenerationArray(array);
                                    }
                                }
                                if (mGenerationTrackers.get(name) != null
@@ -3723,6 +3732,8 @@ public final class Settings {
                                    new GenerationTracker(prefix, array, index, generation,
                                            mGenerationTrackerErrorHandler));
                            currentGeneration = generation;
                        } else {
                            maybeCloseGenerationArray(array);
                        }
                    }
                    if (mGenerationTrackers.get(prefix) != null && currentGeneration