Strictly I think we should be putting each component of an image into _pending_images.
authorCarl Hetherington <cth@carlh.net>
Sun, 6 Nov 2022 22:19:00 +0000 (23:19 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 6 Nov 2022 22:19:04 +0000 (23:19 +0100)
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

index 6f33700a249422314a31cc52102a45cf8e66b4e7..791edb9bcfff2a0c2995b561876098c5d6c8ab70 100644 (file)
@@ -410,18 +410,18 @@ FFmpegFileEncoder::video (shared_ptr<PlayerVideo> 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;