From c42ce0e5b188d6fe0b022f1aec4fdcb04c4835f1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 6 Nov 2022 23:19:00 +0100 Subject: [PATCH] Strictly I think we should be putting each component of an image into _pending_images. We probably get away with only keeping component 0 but I think that could perhaps lead to use-after-free as the Image for components 1 and 2 could go away a bit before it should. --- src/lib/ffmpeg_file_encoder.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc index 6f33700a2..791edb9bc 100644 --- a/src/lib/ffmpeg_file_encoder.cc +++ b/src/lib/ffmpeg_file_encoder.cc @@ -410,18 +410,18 @@ FFmpegFileEncoder::video (shared_ptr video, DCPTime time) auto frame = av_frame_alloc (); DCPOMATIC_ASSERT (frame); - { - boost::mutex::scoped_lock lm (_pending_images_mutex); - auto key = image->data()[0]; - auto iter = _pending_images.find(key); - if (iter != _pending_images.end()) { - iter->second.second++; - } else { - _pending_images[key] = { image, 1 }; + for (int i = 0; i < 3; ++i) { + { + boost::mutex::scoped_lock lm (_pending_images_mutex); + auto key = image->data()[i]; + auto iter = _pending_images.find(key); + if (iter != _pending_images.end()) { + iter->second.second++; + } else { + _pending_images[key] = { image, 1 }; + } } - } - for (int i = 0; i < 3; ++i) { auto buffer = av_buffer_create(image->data()[i], image->stride()[i] * image->size().height, &buffer_free, this, 0); frame->buf[i] = av_buffer_ref (buffer); frame->data[i] = buffer->data; -- 2.30.2