Score and System destructors conflict with each other

• Nov 28, 2018 - 18:43
Reported version
3.0
Priority
P2 - Medium
Type
Development
Frequency
Once
Severity
S2 - Critical
Reproducibility
Always
Status
closed
Regression
Yes
Workaround
No
Project

While experimenting with PR 4166 (do merge it in time, please), I’ve found that trying to delete a MasterScore causes uninitialised memory access (visible in Valgrind, but occasionally causes later program crashes).

I’ve tracked this down to System::~System and Score::~Score both trying to access measures (MeasureBase) which they both have in a list. The problem is, the one that runs first deletes them, while the second one still accesses them. They have different lists, of course…

This is new in 3.x — in 2.x, only one of them dealt with MeasureBases, hence no conflict.

I think the problem comes from the following:

A score has a number of MeasureBases, which are grouped into systems. However, the score also has a list of them, instead of always accessing them via the systems. The system destructor does not destroy the measures, merely sets their system reference to nullptr.

The fix is likely to be complicated and involve restructuring a lot. ☹


Comments

Status PR created fixed

Fixed in branch master, commit e85f3a218c

fix #278969: delete systems before measures on score destruction

As layout-only objects systems need to correctly update the state of
the related measures and spanners on its destruction. For this
reason it may introduce freed memory writing if score is destroyed
in an incorrect order.