App: fixes issue #7628: Crash after creating Sketch for Body
The problem is that inside Transaction::addObjectNew() a transaction object is deleted before removing it from the container. When deleting the corresponding transactional object (i.e. a DocumentObject or ViewProvider) it can happen that it e.g. calls Transaction::addOrRemoveProperty() that now finds the dangling pointer in the container. The safe way is to first remove the object from the container before deleting it.
This commit is contained in:
@@ -194,9 +194,12 @@ void Transaction::addObjectNew(TransactionalObject *Obj)
|
||||
auto pos = index.find(Obj);
|
||||
if (pos != index.end()) {
|
||||
if (pos->second->status == TransactionObject::Del) {
|
||||
delete pos->second;
|
||||
delete pos->first;
|
||||
// first remove the item from the container before deleting it
|
||||
auto second = pos->second;
|
||||
auto first = pos->first;
|
||||
index.erase(pos);
|
||||
delete second;
|
||||
delete first;
|
||||
}
|
||||
else {
|
||||
pos->second->status = TransactionObject::New;
|
||||
|
||||
Reference in New Issue
Block a user