avviddec: Only create the AVBuffer once the stride is validated
authorOlivier Crête <olivier.crete@collabora.com>
Mon, 27 Jul 2015 22:44:53 +0000 (18:44 -0400)
committerOlivier Crête <olivier.crete@collabora.com>
Mon, 27 Jul 2015 22:46:17 +0000 (18:46 -0400)
If it is created earlier and the stride is invalid, then the frame
will be freed and it won't be possible to use it in the fallback path.
Not doing this causes a segfault because it will try to use
already freed memory.

ext/libav/gstavviddec.c

index ee7f2f2..811e51b 100644 (file)
@@ -696,11 +696,6 @@ gst_ffmpegviddec_get_buffer2 (AVCodecContext * context, AVFrame * picture,
       picture->data[c] = GST_VIDEO_FRAME_PLANE_DATA (&dframe->vframe, c);
       picture->linesize[c] = GST_VIDEO_FRAME_PLANE_STRIDE (&dframe->vframe, c);
 
-      if (c == 0) {
-        picture->buf[c] =
-            av_buffer_create (NULL, 0, dummy_free_buffer, dframe, 0);
-      }
-
       /* libav does not allow stride changes currently, fall back to
        * non-direct rendering here:
        * https://bugzilla.gnome.org/show_bug.cgi?id=704769
@@ -733,6 +728,8 @@ gst_ffmpegviddec_get_buffer2 (AVCodecContext * context, AVFrame * picture,
         picture->data[c]);
   }
 
+  picture->buf[0] = av_buffer_create (NULL, 0, dummy_free_buffer, dframe, 0);
+
   /* tell ffmpeg we own this buffer, tranfer the ref we have on the buffer to
    * the opaque data. */
   picture->type = FF_BUFFER_TYPE_USER;