From cda1205c3ee8097905d7df77167dce6c8c352e4a Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 23 Oct 2020 19:47:33 +0200 Subject: [PATCH] App: [skip ci] fix possible segmentation fault when performing a transaction after an undo --- src/App/Document.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 7a7822238ae9..53941d8612ef 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -178,6 +178,7 @@ struct DocumentP bool rollback; bool undoing; ///< document in the middle of undo or redo bool committing; + bool opentransaction; std::bitset<32> StatusBits; int iUndoMode; unsigned int UndoMemSize; @@ -205,6 +206,7 @@ struct DocumentP rollback = false; undoing = false; committing = false; + opentransaction = false; StatusBits.set((size_t)Document::Closable, true); StatusBits.set((size_t)Document::KeepTrailingDigits, true); StatusBits.set((size_t)Document::Restoring, false); @@ -1101,6 +1103,14 @@ int Document::_openTransaction(const char* name, int id) } if (d->iUndoMode) { + // Avoid recursive calls that is possible while + // clearing the redo transactions and will cause + // a double deletion of some transaction and thus + // a segmentation fault + if (d->opentransaction) + return 0; + Base::FlagToggler<> flag(d->opentransaction); + if(id && mUndoMap.find(id)!=mUndoMap.end()) throw Base::RuntimeError("invalid transaction id"); if (d->activeUndoTransaction)