diff --git a/layout/base/src/nsSpaceManager.cpp b/layout/base/src/nsSpaceManager.cpp index 99b5b47b4a1..aaa9affded2 100644 --- a/layout/base/src/nsSpaceManager.cpp +++ b/layout/base/src/nsSpaceManager.cpp @@ -133,7 +133,7 @@ nsSpaceManager::~nsSpaceManager() NS_ASSERTION(!mSavedStates, "states remaining on state stack"); - while (mSavedStates){ + while (mSavedStates && mSavedStates != &mAutoState){ SpaceManagerState *state = mSavedStates; mSavedStates = state->mNext; delete state; @@ -979,7 +979,13 @@ nsSpaceManager::PushState() // Allowing mFloatDamage to accumulate the damage incurred during both // reflows ensures that nothing gets missed. - SpaceManagerState *state = new SpaceManagerState; + SpaceManagerState *state; + + if(mSavedStates) { + state = new SpaceManagerState; + } else { + state = &mAutoState; + } NS_ASSERTION(state, "PushState() failed!"); @@ -994,6 +1000,8 @@ nsSpaceManager::PushState() if (mFrameInfoMap) { state->mLastFrame = mFrameInfoMap->mFrame; + } else { + state->mLastFrame = nsnull; } // Now that we've saved our state, add it to mSavedStates. @@ -1038,11 +1046,14 @@ nsSpaceManager::PopState() mLowestTop = mSavedStates->mLowestTop; // Now that we've restored our state, pop the topmost - // state and delete it. + // state and delete it. Make sure not to delete the mAutoState element + // as it is embeded in this class SpaceManagerState *state = mSavedStates; mSavedStates = mSavedStates->mNext; - delete state; + if(state != &mAutoState) { + delete state; + } } nscoord diff --git a/layout/base/src/nsSpaceManager.h b/layout/base/src/nsSpaceManager.h index a582b559349..273b27121d3 100644 --- a/layout/base/src/nsSpaceManager.h +++ b/layout/base/src/nsSpaceManager.h @@ -332,9 +332,6 @@ protected: nscoord mXMost; nscoord mLowestTop; SpaceManagerState *mNext; - - SpaceManagerState() : mX(0), mY(0), mLastFrame(nsnull), mNext(nsnull) {} - ~SpaceManagerState() {} }; public: @@ -411,6 +408,7 @@ protected: nsIntervalSet mFloatDamage; SpaceManagerState *mSavedStates; + SpaceManagerState mAutoState; protected: FrameInfo* GetFrameInfoFor(nsIFrame* aFrame); diff --git a/layout/generic/nsSpaceManager.cpp b/layout/generic/nsSpaceManager.cpp index 99b5b47b4a1..aaa9affded2 100644 --- a/layout/generic/nsSpaceManager.cpp +++ b/layout/generic/nsSpaceManager.cpp @@ -133,7 +133,7 @@ nsSpaceManager::~nsSpaceManager() NS_ASSERTION(!mSavedStates, "states remaining on state stack"); - while (mSavedStates){ + while (mSavedStates && mSavedStates != &mAutoState){ SpaceManagerState *state = mSavedStates; mSavedStates = state->mNext; delete state; @@ -979,7 +979,13 @@ nsSpaceManager::PushState() // Allowing mFloatDamage to accumulate the damage incurred during both // reflows ensures that nothing gets missed. - SpaceManagerState *state = new SpaceManagerState; + SpaceManagerState *state; + + if(mSavedStates) { + state = new SpaceManagerState; + } else { + state = &mAutoState; + } NS_ASSERTION(state, "PushState() failed!"); @@ -994,6 +1000,8 @@ nsSpaceManager::PushState() if (mFrameInfoMap) { state->mLastFrame = mFrameInfoMap->mFrame; + } else { + state->mLastFrame = nsnull; } // Now that we've saved our state, add it to mSavedStates. @@ -1038,11 +1046,14 @@ nsSpaceManager::PopState() mLowestTop = mSavedStates->mLowestTop; // Now that we've restored our state, pop the topmost - // state and delete it. + // state and delete it. Make sure not to delete the mAutoState element + // as it is embeded in this class SpaceManagerState *state = mSavedStates; mSavedStates = mSavedStates->mNext; - delete state; + if(state != &mAutoState) { + delete state; + } } nscoord diff --git a/layout/generic/nsSpaceManager.h b/layout/generic/nsSpaceManager.h index a582b559349..273b27121d3 100644 --- a/layout/generic/nsSpaceManager.h +++ b/layout/generic/nsSpaceManager.h @@ -332,9 +332,6 @@ protected: nscoord mXMost; nscoord mLowestTop; SpaceManagerState *mNext; - - SpaceManagerState() : mX(0), mY(0), mLastFrame(nsnull), mNext(nsnull) {} - ~SpaceManagerState() {} }; public: @@ -411,6 +408,7 @@ protected: nsIntervalSet mFloatDamage; SpaceManagerState *mSavedStates; + SpaceManagerState mAutoState; protected: FrameInfo* GetFrameInfoFor(nsIFrame* aFrame);