From 5fdf61135785e6388d0eb42edb38efa9cf1fb903 Mon Sep 17 00:00:00 2001 From: saker Date: Mon, 15 Jan 2024 02:34:46 -0500 Subject: [PATCH] Fix memory leaks within tests (#7001) Caused by not calling `Engine::destroy`, as well as creating tracks/clips on the heap and not freeing the memory at the end of the test. Instead of creating tracks/clips on the heap, they are now made on the stack, similar to how the surrounding tests create its objects. --- tests/main.cpp | 1 + tests/src/tracks/AutomationTrackTest.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/main.cpp b/tests/main.cpp index c1a5b5a10..b95f211d4 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -19,5 +19,6 @@ int main(int argc, char* argv[]) if (QTest::qExec(suite, argc, argv) != 0) { ++failed; } } qDebug() << "<<" << failed << "out of"<(Track::create(Track::Type::Instrument, song)); + InstrumentTrack instrumentTrack(song); - MidiClip* midiClip = dynamic_cast(instrumentTrack->createClip(0)); - midiClip->changeLength(TimePos(4, 0)); - Note* note = midiClip->addNote(Note(TimePos(4, 0)), false); + MidiClip midiClip(&instrumentTrack); + midiClip.changeLength(TimePos(4, 0)); + Note* note = midiClip.addNote(Note(TimePos(4, 0)), false); note->createDetuning(); DetuningHelper* dh = note->detuning(); @@ -175,10 +174,11 @@ private slots: auto song = Engine::getSong(); auto patternStore = Engine::patternStore(); PatternTrack patternTrack(song); - Track* automationTrack = Track::create(Track::Type::Automation, patternStore); + AutomationTrack automationTrack(patternStore); + automationTrack.createClipsForPattern(patternStore->numOfPatterns() - 1); - QVERIFY(automationTrack->numOfClips()); - AutomationClip* c1 = dynamic_cast(automationTrack->getClip(0)); + QVERIFY(automationTrack.numOfClips()); + auto c1 = dynamic_cast(automationTrack.getClip(0)); QVERIFY(c1); FloatModel model;