Memory leak: Movements object is not deleted

• May 21, 2018 - 01:38
Reported version
3.0
Type
Functional
Severity
S4 - Minor
Status
active
Project

One of MasterScore constructors commonly used in the code creates an instance of Movements class and holds a pointer to it which can be reassigned via MasterScore::setMovements(). However this object is not deleted by MasterScore destructor which is probably done because several MasterScore objects can hold a pointer to the same Movements instance. The problem is that the Movements object is actually not deleted anywhere, and it leads, for example, to not deleting an UndoStack (which I actually noticed first) which, in turn, should delete objects that were removed from the score during the editing process. In fact, some Movements can be deleted by AlbumManager (mscore/albummanager.cpp) but this does not happen during the usual open/edit/save workflow.

The possible solution could be removing a MasterScore from Movements when reassigning the pointer to it or deleting a MasterScore itself and deleting that Movements object when it gets empty. However perhaps some other solution should be applied.

Steps to reproduce:
1. Mark somehow a construction and destruction of MasterScore and Movements (via qWarning()/breakpoints/whichever may apply)
2. Launch MuseScore
3. Open any score
4. Close the score

Expected results:
MasterScore and Movements objects both get deleted

Actual results:
You will get something like this (Movements and UndoStack are not deleted):

create MasterScore
create Movements
create UndoStack
delete MasterScore

Tested with the last version available in master branch (rev. 1d27005).