Web lists-archives.com

[MPlayer-dev-eng] [PATCH 1/2] libvo/vo_png: Fix AVFrame creation.




From: Michael Niedermayer <michael@xxxxxxxxxxxxxx>

The previous code used uninitialized memory and could randomly crash

Signed-off-by: Michael Niedermayer <michael@xxxxxxxxxxxxxx>
---
 libvo/vo_png.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libvo/vo_png.c b/libvo/vo_png.c
index 06d4a88..109ff4f 100644
--- a/libvo/vo_png.c
+++ b/libvo/vo_png.c
@@ -147,7 +147,7 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
 
 
 static uint32_t draw_image(mp_image_t* mpi){
-    AVFrame pic;
+    AVFrame *pic;
     int buffersize;
     int res, got_pkt;
     char buf[100];
@@ -164,10 +164,11 @@ static uint32_t draw_image(mp_image_t* mpi){
         return 1;
     }
 
+    pic = av_frame_alloc();
     avctx->width = mpi->w;
     avctx->height = mpi->h;
-    pic.data[0] = mpi->planes[0];
-    pic.linesize[0] = mpi->stride[0];
+    pic->data[0] = mpi->planes[0];
+    pic->linesize[0] = mpi->stride[0];
     buffersize = mpi->w * mpi->h * 8;
     if (outbuffer_size < buffersize) {
         av_freep(&outbuffer);
@@ -177,7 +178,8 @@ static uint32_t draw_image(mp_image_t* mpi){
     av_init_packet(&pkt);
     pkt.data = outbuffer;
     pkt.size = outbuffer_size;
-    res = avcodec_encode_video2(avctx, &pkt, &pic, &got_pkt);
+    res = avcodec_encode_video2(avctx, &pkt, pic, &got_pkt);
+    av_frame_free(&pic);
 
     if (res < 0 || !got_pkt) {
  	    mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng);
-- 
1.7.9.5

_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng