mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
r=dp,vidur,beard; close up some memory leaks related to shutdown of the viewer
This commit is contained in:
parent
9b78e0fd9d
commit
2d86782610
@ -1668,6 +1668,19 @@ nsBrowserWindow::Hide()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void DestroyWidget(nsISupports* aWidget)
|
||||
{
|
||||
if (aWidget) {
|
||||
nsIWidget* w;
|
||||
nsresult rv = aWidget->QueryInterface(kIWidgetIID, (void**) &w);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
w->Destroy();
|
||||
NS_RELEASE(w);
|
||||
}
|
||||
NS_RELEASE(aWidget);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::Close()
|
||||
{
|
||||
@ -1678,19 +1691,19 @@ nsBrowserWindow::Close()
|
||||
NS_RELEASE(mWebShell);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mBack);
|
||||
NS_IF_RELEASE(mForward);
|
||||
NS_IF_RELEASE(mLocation);
|
||||
NS_IF_RELEASE(mThrobber);
|
||||
NS_IF_RELEASE(mStatus);
|
||||
DestroyWidget(mBack); mBack = nsnull;
|
||||
DestroyWidget(mForward); mForward = nsnull;
|
||||
DestroyWidget(mLocation); mLocation = nsnull;
|
||||
DestroyWidget(mStatus); mStatus = nsnull;
|
||||
|
||||
// NS_IF_RELEASE(mWindow);
|
||||
if (nsnull != mWindow) {
|
||||
nsIWidget* w = mWindow;
|
||||
w->Destroy();
|
||||
NS_RELEASE(w);
|
||||
if (mThrobber) {
|
||||
mThrobber->Destroy();
|
||||
NS_RELEASE(mThrobber);
|
||||
mThrobber = nsnull;
|
||||
}
|
||||
|
||||
DestroyWidget(mWindow); mWindow = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -175,11 +175,14 @@ nsThrobber::HandleThrobberEvent(nsGUIEvent *aEvent)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
MOZ_DECL_CTOR(nsThrobber);
|
||||
|
||||
PRInt32 nsThrobber::gNumThrobbers;
|
||||
|
||||
// Note: operator new zeros our memory
|
||||
nsThrobber::nsThrobber()
|
||||
{
|
||||
MOZ_CTOR(nsThrobber);
|
||||
NS_INIT_REFCNT();
|
||||
if (0 == gNumThrobbers++) {
|
||||
gThrobbers = new nsVoidArray;
|
||||
@ -189,7 +192,17 @@ nsThrobber::nsThrobber()
|
||||
|
||||
nsThrobber::~nsThrobber()
|
||||
{
|
||||
NS_IF_RELEASE(mWidget);
|
||||
MOZ_DTOR(nsThrobber);
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void
|
||||
nsThrobber::Destroy()
|
||||
{
|
||||
if (mWidget) {
|
||||
mWidget->Destroy();
|
||||
NS_RELEASE(mWidget);
|
||||
}
|
||||
RemoveThrobber(this);
|
||||
DestroyThrobberImages();
|
||||
|
||||
@ -200,7 +213,34 @@ nsThrobber::~nsThrobber()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LOG_REFCNTS
|
||||
extern "C" {
|
||||
void __log_addref(void* p, int oldrc, int newrc);
|
||||
void __log_release(void* p, int oldrc, int newrc);
|
||||
}
|
||||
|
||||
nsrefcnt nsThrobber::AddRef(void)
|
||||
{
|
||||
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
|
||||
__log_addref((void*) this, mRefCnt, mRefCnt + 1);
|
||||
return ++mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt nsThrobber::Release(void)
|
||||
{
|
||||
__log_release((void*) this, mRefCnt, mRefCnt - 1);
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||
if (--mRefCnt == 0) {
|
||||
NS_DELETEXPCOM(this);
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsThrobber, kIImageObserverIID)
|
||||
#else
|
||||
NS_IMPL_ISUPPORTS(nsThrobber, kIImageObserverIID)
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
nsThrobber::Init(nsIWidget* aParent, const nsRect& aBounds, const nsString& aFileNameMask, PRInt32 aNumImages)
|
||||
@ -373,5 +413,6 @@ nsThrobber::DestroyThrobberImages()
|
||||
|
||||
if (mImages) {
|
||||
delete mImages;
|
||||
mImages = nsnull;
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
// nsThrobber
|
||||
nsresult Init(nsIWidget* aParent, const nsRect& aBounds,
|
||||
const nsString& aFileNameMask, PRInt32 aNumImages);
|
||||
void Destroy();
|
||||
nsresult MoveTo(PRInt32 aX, PRInt32 aY);
|
||||
nsresult Show();
|
||||
nsresult Hide();
|
||||
|
@ -164,12 +164,12 @@ nsWebCrawler::nsWebCrawler(nsViewerApp* aViewer)
|
||||
mDelay = 0;
|
||||
mMaxPages = -1;
|
||||
mRecord = nsnull;
|
||||
mLinkTag = NS_NewAtom("a");
|
||||
mFrameTag = NS_NewAtom("frame");
|
||||
mIFrameTag = NS_NewAtom("iframe");
|
||||
mHrefAttr = NS_NewAtom("href");
|
||||
mSrcAttr = NS_NewAtom("src");
|
||||
mBaseHrefAttr = NS_NewAtom("_base_href");
|
||||
mLinkTag = getter_AddRefs(NS_NewAtom("a"));
|
||||
mFrameTag = getter_AddRefs(NS_NewAtom("frame"));
|
||||
mIFrameTag = getter_AddRefs(NS_NewAtom("iframe"));
|
||||
mHrefAttr = getter_AddRefs(NS_NewAtom("href"));
|
||||
mSrcAttr = getter_AddRefs(NS_NewAtom("src"));
|
||||
mBaseHrefAttr = getter_AddRefs(NS_NewAtom("_base_href"));
|
||||
mVisited = new AtomHashTable();
|
||||
mVerbose = nsnull;
|
||||
mRegressing = PR_FALSE;
|
||||
@ -191,12 +191,6 @@ nsWebCrawler::~nsWebCrawler()
|
||||
FreeStrings(mAvoidDomains);
|
||||
NS_IF_RELEASE(mBrowser);
|
||||
NS_IF_RELEASE(mTimer);
|
||||
NS_IF_RELEASE(mLinkTag);
|
||||
NS_IF_RELEASE(mFrameTag);
|
||||
NS_IF_RELEASE(mIFrameTag);
|
||||
NS_IF_RELEASE(mHrefAttr);
|
||||
NS_IF_RELEASE(mSrcAttr);
|
||||
NS_IF_RELEASE(mBaseHrefAttr);
|
||||
delete mVisited;
|
||||
}
|
||||
|
||||
@ -648,8 +642,8 @@ nsWebCrawler::RecordLoadedURL(const nsString& aURL)
|
||||
void
|
||||
nsWebCrawler::FindURLsIn(nsIDocument* aDocument, nsIContent* aNode)
|
||||
{
|
||||
nsIAtom* atom;
|
||||
aNode->GetTag(atom);
|
||||
nsCOMPtr<nsIAtom> atom;
|
||||
aNode->GetTag(*getter_AddRefs(atom));
|
||||
if ((atom == mLinkTag) || (atom == mFrameTag) || (atom == mIFrameTag)) {
|
||||
// Get absolute url that tag targets
|
||||
nsAutoString base, src, absURLSpec;
|
||||
@ -668,7 +662,7 @@ nsWebCrawler::FindURLsIn(nsIDocument* aDocument, nsIContent* aNode)
|
||||
rv = NS_MakeAbsoluteURI(src, docURL, absURLSpec);
|
||||
#endif // NECKO
|
||||
if (NS_OK == rv) {
|
||||
nsIAtom* urlAtom = NS_NewAtom(absURLSpec);
|
||||
nsCOMPtr<nsIAtom> urlAtom = getter_AddRefs(NS_NewAtom(absURLSpec));
|
||||
if (0 == mVisited->Get(urlAtom)) {
|
||||
// Remember the URL as visited so that we don't go there again
|
||||
mVisited->Put(urlAtom, "visited");
|
||||
@ -695,11 +689,10 @@ nsWebCrawler::FindURLsIn(nsIDocument* aDocument, nsIContent* aNode)
|
||||
printf("'\n");
|
||||
}
|
||||
}
|
||||
NS_RELEASE(urlAtom);
|
||||
}
|
||||
NS_RELEASE(docURL);
|
||||
}
|
||||
NS_IF_RELEASE(atom);
|
||||
|
||||
PRBool canHaveKids;
|
||||
aNode->CanContainChildren(canHaveKids);
|
||||
if (canHaveKids) {
|
||||
|
@ -19,12 +19,13 @@
|
||||
#ifndef nsWebCrawler_h___
|
||||
#define nsWebCrawler_h___
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIBrowserWindow.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIAtom.h"
|
||||
|
||||
class nsIAtom;
|
||||
class nsIContent;
|
||||
class nsIDocument;
|
||||
class nsITimer;
|
||||
@ -151,12 +152,12 @@ protected:
|
||||
nsViewerApp* mViewer;
|
||||
nsITimer* mTimer;
|
||||
FILE* mRecord;
|
||||
nsIAtom* mLinkTag;
|
||||
nsIAtom* mFrameTag;
|
||||
nsIAtom* mIFrameTag;
|
||||
nsIAtom* mHrefAttr;
|
||||
nsIAtom* mSrcAttr;
|
||||
nsIAtom* mBaseHrefAttr;
|
||||
nsCOMPtr<nsIAtom> mLinkTag;
|
||||
nsCOMPtr<nsIAtom> mFrameTag;
|
||||
nsCOMPtr<nsIAtom> mIFrameTag;
|
||||
nsCOMPtr<nsIAtom> mHrefAttr;
|
||||
nsCOMPtr<nsIAtom> mSrcAttr;
|
||||
nsCOMPtr<nsIAtom> mBaseHrefAttr;
|
||||
AtomHashTable* mVisited;
|
||||
nsString mOutputDir;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user