Skip to content

Commit

Permalink
fix #1592 leaking some MLT objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Oct 6, 2024
1 parent f922f5b commit 4a49c74
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
37 changes: 23 additions & 14 deletions src/commands/timelinecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,12 +1493,15 @@ void AddTrackCommand::redo()
else
m_trackIndex = m_model.addAudioTrack();
int mlt_index = m_model.trackList().at(m_trackIndex).mlt_index;
Mlt::Producer producer(m_model.tractor()->multitrack()->track(mlt_index));
if (producer.is_valid()) {
std::unique_ptr<Mlt::Multitrack> multitrack(m_model.tractor()->multitrack());
if (!multitrack || !multitrack->is_valid())
return;
std::unique_ptr<Mlt::Producer> producer(multitrack->track(mlt_index));
if (producer && producer->is_valid()) {
if (m_uuid.isNull()) {
m_uuid = MLT.ensureHasUuid(producer);
m_uuid = MLT.ensureHasUuid(*producer);
} else {
MLT.setUuid(producer, m_uuid);
MLT.setUuid(*producer, m_uuid);
}
}
}
Expand Down Expand Up @@ -1532,12 +1535,15 @@ void InsertTrackCommand::redo()
"video");
m_model.insertTrack(m_trackIndex, m_trackType);
int mlt_index = m_model.trackList().at(m_trackIndex).mlt_index;
Mlt::Producer producer(m_model.tractor()->multitrack()->track(mlt_index));
if (producer.is_valid()) {
std::unique_ptr<Mlt::Multitrack> multitrack(m_model.tractor()->multitrack());
if (!multitrack || !multitrack->is_valid())
return;
std::unique_ptr<Mlt::Producer> producer(multitrack->track(mlt_index));
if (producer && producer->is_valid()) {
if (m_uuid.isNull()) {
m_uuid = MLT.ensureHasUuid(producer);
m_uuid = MLT.ensureHasUuid(*producer);
} else {
MLT.setUuid(producer, m_uuid);
MLT.setUuid(*producer, m_uuid);
}
}
}
Expand Down Expand Up @@ -1839,12 +1845,15 @@ void DetachAudioCommand::redo()
if (m_targetTrackIndex > -1) {
// Set the producer UUID on the new track.
int mlt_index = model->trackList().at(m_targetTrackIndex).mlt_index;
Mlt::Producer producer(model->tractor()->multitrack()->track(mlt_index));
if (producer.is_valid()) {
if (m_uuid.isNull()) {
m_uuid = MLT.ensureHasUuid(producer);
} else {
MLT.setUuid(producer, m_uuid);
std::unique_ptr<Mlt::Multitrack> multitrack(model->tractor()->multitrack());
if (multitrack && !multitrack->is_valid()) {
std::unique_ptr<Mlt::Producer> producer(multitrack->track(mlt_index));
if (producer && producer->is_valid()) {
if (m_uuid.isNull()) {
m_uuid = MLT.ensureHasUuid(*producer);
} else {
MLT.setUuid(*producer, m_uuid);
}
}
}
m_undoHelper.recordBeforeState();
Expand Down
5 changes: 2 additions & 3 deletions src/docks/timelinedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2539,12 +2539,11 @@ void TimelineDock::emitSelectedFromSelection()

if (selection().isEmpty() && m_selection.selectedTrack > -1) {
int i = m_model.trackList().at(m_selection.selectedTrack).mlt_index;
Mlt::Producer *producer = m_model.tractor()->track(i);
std::unique_ptr<Mlt::Producer>producer(m_model.tractor()->track(i));
if (producer && producer->is_valid()) {
producer->set(kTrackIndexProperty, m_selection.selectedTrack);
emit selected(producer);
emit selected(producer.get());
}
delete producer;
return;
}

Expand Down
20 changes: 8 additions & 12 deletions src/models/multitrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2467,12 +2467,11 @@ void MultitrackModel::consolidateBlanksAllTracks()
if (!m_tractor) return;
int i = 0;
foreach (Track t, m_trackList) {
Mlt::Producer *track = m_tractor->track(t.mlt_index);
if (track) {
std::unique_ptr<Mlt::Producer> track(m_tractor->track(t.mlt_index));
if (track && track->is_valid()) {
Mlt::Playlist playlist(*track);
consolidateBlanks(playlist, i);
}
delete track;
++i;
}
}
Expand Down Expand Up @@ -2518,11 +2517,11 @@ void MultitrackModel::adjustBackgroundDuration()
{
if (!m_tractor) return;
int duration = getDuration();
Mlt::Producer *track = m_tractor->track(0);
if (track) {
std::unique_ptr<Mlt::Producer> track(m_tractor->track(0));
if (track && track->is_valid()) {
Mlt::Playlist playlist(*track);
Mlt::Producer *clip = playlist.get_clip(0);
if (clip) {
std::unique_ptr<Mlt::Producer> clip(playlist.get_clip(0));
if (clip && clip->is_valid()) {
if (duration != clip->parent().get_length()) {
clip->parent().set("length", clip->parent().frames_to_time(duration, mlt_time_clock));
clip->parent().set_in_and_out(0, duration - 1);
Expand All @@ -2531,9 +2530,7 @@ void MultitrackModel::adjustBackgroundDuration()
playlist.resize_clip(0, 0, duration - 1);
emit durationChanged();
}
delete clip;
}
delete track;
}
}

Expand Down Expand Up @@ -3651,10 +3648,9 @@ void MultitrackModel::addBlackTrackIfNeeded()
if (!found) {
// Move all existing tracks down by 1.
for (int i = n; i > 0; i++) {
Mlt::Producer *producer = m_tractor->track(n - 1);
if (producer)
std::unique_ptr<Mlt::Producer> producer(m_tractor->track(n - 1));
if (producer && producer->is_valid())
m_tractor->set_track(*producer, n);
delete producer;
}
Mlt::Producer producer(MLT.profile(), "color:0");
producer.set("mlt_image_format", "rgba");
Expand Down

0 comments on commit 4a49c74

Please sign in to comment.