13
0

RhythmFerret: fix heap-use-after-free

After splitting regions, the AudioRegionView of the original
Region no longer exists when the RhythmFerret calls
`clear_transients()` at the end.
This commit is contained in:
Robin Gareus 2023-10-31 04:31:08 +01:00
parent eebc902564
commit 49abbe5777
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 11 additions and 9 deletions

View File

@ -231,7 +231,9 @@ RhythmFerret::run_analysis ()
clear_transients (); clear_transients ();
regions_with_transients = editor.get_selection().regions; for (auto const& rv : editor.get_selection().regions) {
regions_with_transients.push_back (rv->region ());
}
current_results.clear (); current_results.clear ();
@ -239,22 +241,22 @@ RhythmFerret::run_analysis ()
return; return;
} }
for (RegionSelection::iterator i = regions_with_transients.begin(); i != regions_with_transients.end(); ++i) { for (auto const& r : regions_with_transients) {
std::shared_ptr<AudioReadable> rd = std::static_pointer_cast<AudioRegion> ((*i)->region()); std::shared_ptr<AudioReadable> rd = std::static_pointer_cast<AudioRegion> (r);
switch (get_analysis_mode()) { switch (get_analysis_mode()) {
case PercussionOnset: case PercussionOnset:
run_percussion_onset_analysis (rd, (*i)->region()->position_sample(), current_results); run_percussion_onset_analysis (rd, r->position_sample(), current_results);
break; break;
case NoteOnset: case NoteOnset:
run_note_onset_analysis (rd, (*i)->region()->position_sample(), current_results); run_note_onset_analysis (rd, r->position_sample(), current_results);
break; break;
default: default:
break; break;
} }
(*i)->region()->set_onsets (current_results); r->set_onsets (current_results);
current_results.clear(); current_results.clear();
} }
} }
@ -448,8 +450,8 @@ RhythmFerret::clear_transients ()
{ {
current_results.clear (); current_results.clear ();
for (RegionSelection::iterator i = regions_with_transients.begin(); i != regions_with_transients.end(); ++i) { for (auto const& r : regions_with_transients) {
(*i)->region()->set_onsets (current_results); r->set_onsets (current_results);
} }
regions_with_transients.clear (); regions_with_transients.clear ();

View File

@ -109,7 +109,7 @@ private:
void clear_transients (); void clear_transients ();
/** Regions that we have added transient marks to */ /** Regions that we have added transient marks to */
RegionSelection regions_with_transients; ARDOUR::RegionList regions_with_transients;
AnalysisMode get_analysis_mode () const; AnalysisMode get_analysis_mode () const;
Action get_action() const; Action get_action() const;