Skip to content

Commit

Permalink
Bug 1661862 - Don't assert when we leak nsSHistories. r=peterv
Browse files Browse the repository at this point in the history
nsSHistories are kept in a linked list. When we leak one, we hit
a linked list assertion. This patch works around that by adding
a helper that removes everything from the list before it is
destroyed. We'll still have test failures, but they'll be in
the leak checker, which is hopefully more informative.

Differential Revision: https://phabricator.services.mozilla.com/D145977
  • Loading branch information
amccreight committed May 11, 2022
1 parent 56df970 commit 5fc5617
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docshell/shistory/nsSHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,19 @@ static const char* kObservedPrefs[] = {PREF_SHISTORY_SIZE,
PREF_FISSION_BFCACHEINPARENT, nullptr};

static int32_t gHistoryMaxSize = 50;
// List of all SHistory objects, used for content viewer cache eviction
static LinkedList<nsSHistory> gSHistoryList;

// List of all SHistory objects, used for content viewer cache eviction.
// When being destroyed, this helper removes everything from the list to avoid
// assertions when we leak.
struct ListHelper {
#ifdef DEBUG
~ListHelper() { mList.clear(); }
#endif // DEBUG

LinkedList<nsSHistory> mList;
};

static ListHelper gSHistoryList;
// Max viewers allowed total, across all SHistory objects - negative default
// means we will calculate how many viewers to cache based on total memory
int32_t nsSHistory::sHistoryMaxTotalViewers = -1;
Expand Down Expand Up @@ -248,7 +259,7 @@ nsSHistory::nsSHistory(BrowsingContext* aRootBC)
}

// Add this new SHistory object to the list
gSHistoryList.insertBack(this);
gSHistoryList.mList.insertBack(this);

// Init mHistoryTracker on setting mRootBC so we can bind its event
// target to the tabGroup.
Expand Down Expand Up @@ -1595,7 +1606,7 @@ void nsSHistory::GloballyEvictContentViewers() {

nsTArray<EntryAndDistance> entries;

for (auto shist : gSHistoryList) {
for (auto shist : gSHistoryList.mList) {
// Maintain a list of the entries which have viewers and belong to
// this particular shist object. We'll add this list to the global list,
// |entries|, eventually.
Expand Down

0 comments on commit 5fc5617

Please sign in to comment.