musescore / musescore/MuseScore

Memory leaks in instrument ownership model

Open
#32,722 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs review
Dominant language
C++
Stars
15.1k
Forks
3.3k
Avg merge
2d 2h
Merged PRs (30d)
91

Description

Multiple memory leaks and crashes exist in instrument management:

Memory leaks: Part destructor missing, instruments never freed
Double-free risk: InstrumentChange deletes shared pointers
Use-after-free: setInstruments({}) after shallow-copy leaves dangling pointers
EID assertion: No idempotent registration check causes crashes on memory reuse
Thread-safety: Parallel excerpt serialization races on MIDI mapping

Root cause:

No ownership model for Instrument pointers shared between InstrumentChange and Part::m_instruments.

Checklist
  • This report follows the guidelines for reporting bugs and issues
  • I have verified that this issue has not been logged before, by searching the issue tracker for similar issues
  • I have attached all requested files and information to this report
  • I have attempted to identify the root problem as concisely as possible, and have used minimal reproducible examples where possible

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report names no files or tests. Start by locating Part, InstrumentChange, Part::m_instruments, and the excerpt serialization path, then trace pointer ownership and concurrent MIDI mapping access. Done requires resolving the listed leaks, double-free and use-after-free risks, registration assertion, and serialization race with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.