From 91063d56d4b3e171c2716ff85074aae000081bfe Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 13 Apr 2004 00:27:29 +0000 Subject: [PATCH] Make sure to null out mStyleSet if Init() fails, since the caller will delete it in that case. Bug 240240, r+sr=bryner git-svn-id: svn://10.0.0.236/trunk@154741 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsPresShell.cpp | 20 +++++++++++++++++--- mozilla/layout/html/base/src/nsPresShell.cpp | 20 +++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 12e4c510247..ec6712f8a53 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -1693,6 +1693,10 @@ PresShell::Init(nsIDocument* aDocument, nsresult result = aStyleSet->Init(aPresContext); NS_ENSURE_SUCCESS(result, result); + // From this point on, any time we return an error we need to make + // sure to null out mStyleSet first, since an error return from this + // method will cause the caller to delete the style set, so we don't + // want to delete it in our destructor. mStyleSet = aStyleSet; // Set the compatibility mode after attaching the pres context and @@ -1704,16 +1708,24 @@ PresShell::Init(nsIDocument* aDocument, SetPreferenceStyleRules(PR_FALSE); mSelection = do_CreateInstance(kFrameSelectionCID, &result); - if (NS_FAILED(result)) + if (NS_FAILED(result)) { + mStyleSet = nsnull; return result; + } // Create and initialize the frame manager result = FrameManager()->Init(this, mStyleSet); - NS_ENSURE_SUCCESS(result, result); + if (NS_FAILED(result)) { + NS_WARNING("Frame manager initialization failed"); + mStyleSet = nsnull; + return result; + } result = mSelection->Init((nsIFocusTracker *) this, nsnull); - if (NS_FAILED(result)) + if (NS_FAILED(result)) { + mStyleSet = nsnull; return result; + } // Important: this has to happen after the selection has been set up #ifdef SHOW_CARET // make the caret @@ -1744,6 +1756,7 @@ PresShell::Init(nsIDocument* aDocument, if (!mEventQueueService) { NS_WARNING("couldn't get event queue service"); + mStyleSet = nsnull; return NS_ERROR_FAILURE; } @@ -1765,6 +1778,7 @@ PresShell::Init(nsIDocument* aDocument, mObserverService = do_GetService("@mozilla.org/observer-service;1", &result); if (NS_FAILED(result)) { + mStyleSet = nsnull; return result; } diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 12e4c510247..ec6712f8a53 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -1693,6 +1693,10 @@ PresShell::Init(nsIDocument* aDocument, nsresult result = aStyleSet->Init(aPresContext); NS_ENSURE_SUCCESS(result, result); + // From this point on, any time we return an error we need to make + // sure to null out mStyleSet first, since an error return from this + // method will cause the caller to delete the style set, so we don't + // want to delete it in our destructor. mStyleSet = aStyleSet; // Set the compatibility mode after attaching the pres context and @@ -1704,16 +1708,24 @@ PresShell::Init(nsIDocument* aDocument, SetPreferenceStyleRules(PR_FALSE); mSelection = do_CreateInstance(kFrameSelectionCID, &result); - if (NS_FAILED(result)) + if (NS_FAILED(result)) { + mStyleSet = nsnull; return result; + } // Create and initialize the frame manager result = FrameManager()->Init(this, mStyleSet); - NS_ENSURE_SUCCESS(result, result); + if (NS_FAILED(result)) { + NS_WARNING("Frame manager initialization failed"); + mStyleSet = nsnull; + return result; + } result = mSelection->Init((nsIFocusTracker *) this, nsnull); - if (NS_FAILED(result)) + if (NS_FAILED(result)) { + mStyleSet = nsnull; return result; + } // Important: this has to happen after the selection has been set up #ifdef SHOW_CARET // make the caret @@ -1744,6 +1756,7 @@ PresShell::Init(nsIDocument* aDocument, if (!mEventQueueService) { NS_WARNING("couldn't get event queue service"); + mStyleSet = nsnull; return NS_ERROR_FAILURE; } @@ -1765,6 +1778,7 @@ PresShell::Init(nsIDocument* aDocument, mObserverService = do_GetService("@mozilla.org/observer-service;1", &result); if (NS_FAILED(result)) { + mStyleSet = nsnull; return result; }