Bug 619797 - imgRequest::Init should manage observer more carefully, r+a=joedrew

This commit is contained in:
timeless@mozdev.org 2011-01-09 09:48:00 -08:00
parent eff574fdb4
commit 5d6d929c9e

View File

@ -241,19 +241,15 @@ nsresult imgRequest::Init(nsIURI *aURI,
// Register our pref observer if it hasn't been done yet.
if (NS_UNLIKELY(!gRegisteredPrefObserver)) {
imgRequestPrefObserver *observer = new imgRequestPrefObserver();
if (observer) {
nsCOMPtr<nsIPrefBranch2> branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (branch) {
branch->AddObserver(DISCARD_PREF, observer, PR_FALSE);
branch->AddObserver(DECODEONDRAW_PREF, observer, PR_FALSE);
branch->AddObserver(DISCARD_TIMEOUT_PREF, observer, PR_FALSE);
ReloadPrefs(branch);
gRegisteredPrefObserver = PR_TRUE;
}
nsCOMPtr<nsIPrefBranch2> branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (branch) {
nsCOMPtr<nsIObserver> observer(new imgRequestPrefObserver());
branch->AddObserver(DISCARD_PREF, observer, PR_FALSE);
branch->AddObserver(DECODEONDRAW_PREF, observer, PR_FALSE);
branch->AddObserver(DISCARD_TIMEOUT_PREF, observer, PR_FALSE);
ReloadPrefs(branch);
gRegisteredPrefObserver = PR_TRUE;
}
else
delete observer;
}
return NS_OK;