From 1c79d553f313f733179dceb9a69437023fe1a748 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Thu, 3 Oct 2002 21:27:05 +0000 Subject: [PATCH] Fix bug # 172450: plug ever-increasing memory leaks. When new internet search results are added, old nodes were being removed, but old attributes hanging off of the old nodes need to be cleared out also (but, IFF there are no other references to the old search result nodes in the graph.) r=sgehani sr=jag --- .../search/src/nsInternetSearchService.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/xpfe/components/search/src/nsInternetSearchService.cpp b/xpfe/components/search/src/nsInternetSearchService.cpp index f9882602a30d..e807679c222b 100755 --- a/xpfe/components/search/src/nsInternetSearchService.cpp +++ b/xpfe/components/search/src/nsInternetSearchService.cpp @@ -2873,6 +2873,44 @@ InternetSearchDataSource::ClearResults(PRBool flushLastSearchRef) { mInner->Unassert(kNC_LastSearchRoot, kNC_Child, child); } + + // *after* (so that we won't thrash the XUL template builder) unasserting + // child node, determine if there are any other references to the child + // node in the graph + + PRBool hasInArcs = PR_FALSE; + nsCOMPtr inArcs; + if (NS_FAILED(mInner->ArcLabelsIn(child, getter_AddRefs(inArcs)) || + (!inArcs))) + continue; + if (NS_FAILED(inArcs->HasMoreElements(&hasInArcs)) || + (hasInArcs == PR_TRUE)) + continue; + + // no other references, so also unassert any outgoing arcs + + nsCOMPtr outArcs; + if (NS_FAILED(mInner->ArcLabelsOut(child, getter_AddRefs(outArcs)) || + (!outArcs))) + continue; + PRBool hasMoreOutArcs = PR_TRUE; + while (hasMoreOutArcs == PR_TRUE) + { + if (NS_FAILED(outArcs->HasMoreElements(&hasMoreOutArcs)) || + (hasMoreOutArcs == PR_FALSE)) + break; + nsCOMPtr outArc; + if (NS_FAILED(outArcs->GetNext(getter_AddRefs(outArc)))) + break; + nsCOMPtr property (do_QueryInterface(outArc)); + if (!property) + continue; + nsCOMPtr target; + if (NS_FAILED(mInner->GetTarget(child, property, PR_TRUE, + getter_AddRefs(target))) || (!target)) + continue; + mInner->Unassert(child, property, target); + } } }