summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/source/core/data/postit.cxx7
1 files changed, 6 insertions, 1 deletions
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index e8afbb2479dc..7d3effc671fd 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -1130,6 +1130,7 @@ void ScPostIt::RemoveCaption()
ScDrawLayer* pDrawLayer = mrDoc.GetDrawLayer();
if (maNoteData.mxCaption && (pDrawLayer == maNoteData.mxCaption->GetModel()))
maNoteData.mxCaption.removeFromDrawPageAndFree();
+
// Either the caption object is gone or, because of Undo or clipboard is
// held in at least two instances, or only one instance in Undo because the
// original sheet in this document is just deleted, or the Undo document is
@@ -1137,7 +1138,11 @@ void ScPostIt::RemoveCaption()
// Let's detect other use cases..
assert(!maNoteData.mxCaption || maNoteData.mxCaption.getRefs() >= 2 ||
(!mrDoc.IsUndo() && !mrDoc.IsClipboard()) || (mrDoc.IsUndo() && mrDoc.IsInDtorClear()));
- maNoteData.mxCaption.reset(nullptr);
+
+ // Forget the caption object if removeFromDrawPageAndFree() above did not
+ // free it.
+ if (maNoteData.mxCaption)
+ maNoteData.mxCaption.forget();
}
ScCaptionPtr ScNoteUtil::CreateTempCaption(