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

Commit bae5a32b authored by Songchun Fan's avatar Songchun Fan Committed by Song Chun Fan
Browse files

[SettingsProvider] always destroy old tracker before inserting a new one

Previously, the destroying of the old tracker and the insertion of the
new tracker are in two separate synchronized blocks. This creates the
opportunity of a race condition, where another tracker is inserted
between the two synchronized blocks, and is never properly destroyed,
which leads to memory leaks. This CL fixes that.

BUG: 277448672
Test: builds; this is a theoretical fix as I couldn't reproduce the bug
locally

Change-Id: Ia0fbcee6f56dd1035e68d20f3730b4d34e2085b6
parent acca83b6
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -3583,6 +3583,12 @@ public final class Settings {
                                                    + " and user:" + userHandle
                                                    + " with index:" + index);
                                        }
                                        // Always make sure to close any pre-existing tracker before
                                        // replacing it, to prevent memory leaks
                                        var oldTracker = mGenerationTrackers.get(name);
                                        if (oldTracker != null) {
                                            oldTracker.destroy();
                                        }
                                        mGenerationTrackers.put(name, new GenerationTracker(name,
                                                array, index, generation,
                                                mGenerationTrackerErrorHandler));
@@ -3805,6 +3811,12 @@ public final class Settings {
                                        + " in package:" + cr.getPackageName()
                                        + " with index:" + index);
                            }
                            // Always make sure to close any pre-existing tracker before
                            // replacing it, to prevent memory leaks
                            var oldTracker = mGenerationTrackers.get(prefix);
                            if (oldTracker != null) {
                                oldTracker.destroy();
                            }
                            mGenerationTrackers.put(prefix,
                                    new GenerationTracker(prefix, array, index, generation,
                                            mGenerationTrackerErrorHandler));