From f847d9f9a41c61207f56bfd4d3f8c5d74803db2b Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Tue, 2 Nov 1999 05:16:41 +0000 Subject: [PATCH] fixed bug 17689 r=jfrancis --- editor/base/nsHTMLEditor.cpp | 12 +++++++++++- editor/libeditor/html/nsHTMLEditor.cpp | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index 2dbb94b70629..540cc68eec73 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -227,12 +227,22 @@ nsHTMLEditor::nsHTMLEditor() nsHTMLEditor::~nsHTMLEditor() { + /* first, delete the transaction manager if there is one. + this will release any remaining transactions. + this is important because transactions can hold onto the atoms (gTypingTxnName, ...) + and to make the optimization (holding refcounted statics) work correctly, + the editor instance needs to hold the last refcount. + If you get this wrong, expect to deref a garbage gTypingTxnName pointer if you bring up a second editor. + */ + if (mTxnMgr) { + mTxnMgr = 0; + } nsrefcnt refCount=0; if (gTypingTxnName) // we addref'd in the constructor { // want to release it without nulling out the pointer. refCount = gTypingTxnName->Release(); if (0==refCount) { - gTypingTxnName = nsnull; + gTypingTxnName = nsnull; } } diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 2dbb94b70629..540cc68eec73 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -227,12 +227,22 @@ nsHTMLEditor::nsHTMLEditor() nsHTMLEditor::~nsHTMLEditor() { + /* first, delete the transaction manager if there is one. + this will release any remaining transactions. + this is important because transactions can hold onto the atoms (gTypingTxnName, ...) + and to make the optimization (holding refcounted statics) work correctly, + the editor instance needs to hold the last refcount. + If you get this wrong, expect to deref a garbage gTypingTxnName pointer if you bring up a second editor. + */ + if (mTxnMgr) { + mTxnMgr = 0; + } nsrefcnt refCount=0; if (gTypingTxnName) // we addref'd in the constructor { // want to release it without nulling out the pointer. refCount = gTypingTxnName->Release(); if (0==refCount) { - gTypingTxnName = nsnull; + gTypingTxnName = nsnull; } }