From ca76f0133ad3d17fabab3f7f5109939a161bcc82 Mon Sep 17 00:00:00 2001 From: "inaky.gonzalez%intel.com" Date: Fri, 23 Jun 2000 00:14:22 +0000 Subject: [PATCH] Bug #39323. Change nsSoftwareUpdate::mMasterListener to be a dynamically allocated object instead of a member, so we don't have to do ugly tricks AddRefing it manually not to get it destroyed (and thus segfaulting). r=waterson,dvedit a=dvedit --- xpinstall/src/nsSoftwareUpdate.cpp | 33 ++++++++++++++++++++++-------- xpinstall/src/nsSoftwareUpdate.h | 13 ++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/xpinstall/src/nsSoftwareUpdate.cpp b/xpinstall/src/nsSoftwareUpdate.cpp index 1fcff0578fd1..824a96709227 100644 --- a/xpinstall/src/nsSoftwareUpdate.cpp +++ b/xpinstall/src/nsSoftwareUpdate.cpp @@ -125,8 +125,9 @@ nsSoftwareUpdate::nsSoftwareUpdate() mReg(0) { NS_INIT_ISUPPORTS(); - mMasterListener.AddRef(); // inflate refcount so it doesn't go away early - + mMasterListener = new nsTopProgressListener; + NS_IF_ADDREF (mMasterListener); + mLock = PR_NewLock(); /***************************************/ @@ -179,7 +180,7 @@ nsSoftwareUpdate::~nsSoftwareUpdate() NR_ShutdownRegistry(); //NS_IF_RELEASE( mProgramDir ); - + NS_IF_RELEASE (mMasterListener); mInstance = nsnull; } @@ -261,9 +262,13 @@ nsSoftwareUpdate::RegisterListener(nsIXPIListener *aListener) // register a Listener, you can not remove it. This should at some // point be fixed. - (void) mMasterListener.RegisterListener(aListener); - + if (mMasterListener) + { + mMasterListener->RegisterListener(aListener); return NS_OK; + } + else + return NS_ERROR_FAILURE; } NS_IMETHODIMP @@ -273,17 +278,27 @@ nsSoftwareUpdate::GetMasterListener(nsIXPIListener **aListener) if (!aListener) return NS_ERROR_NULL_POINTER; - NS_ADDREF(&mMasterListener); - *aListener = &mMasterListener; - return NS_OK; + if (mMasterListener) + { + NS_ADDREF (mMasterListener); + *aListener = mMasterListener; + return NS_OK; + } + else + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsSoftwareUpdate::SetActiveListener(nsIXPIListener *aListener) { - mMasterListener.SetActiveListener(aListener); + if (mMasterListener) + { + mMasterListener->SetActiveListener (aListener); return NS_OK; + } + else + return NS_ERROR_FAILURE; } NS_IMETHODIMP diff --git a/xpinstall/src/nsSoftwareUpdate.h b/xpinstall/src/nsSoftwareUpdate.h index ded74cd8db6e..df2d5df559d7 100644 --- a/xpinstall/src/nsSoftwareUpdate.h +++ b/xpinstall/src/nsSoftwareUpdate.h @@ -13,6 +13,7 @@ #include "prlock.h" //#include "mozreg.h" #include "NSReg.h" +#include "nsCOMPtr.h" class nsInstallInfo; @@ -91,13 +92,13 @@ class nsSoftwareUpdate: public nsIAppShellComponent, nsresult RunNextInstall(); nsresult RegisterNameset(); - PRLock* mLock; - PRBool mInstalling; - PRBool mStubLockout; - nsVoidArray mJarInstallQueue; - nsTopProgressListener mMasterListener; + PRLock* mLock; + PRBool mInstalling; + PRBool mStubLockout; + nsVoidArray mJarInstallQueue; + nsTopProgressListener *mMasterListener; - HREG mReg; + HREG mReg; };