[PATCH 1/2] libvo/vo_png: Fix AVFrame creation.
From: Michael Niedermayer <michael@niedermayer.cc> The previous code used uninitialized memory and could randomly crash Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- 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
From: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libvo/vo_png.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libvo/vo_png.c b/libvo/vo_png.c index 109ff4f..38a4097 100644 --- a/libvo/vo_png.c +++ b/libvo/vo_png.c @@ -167,6 +167,9 @@ static uint32_t draw_image(mp_image_t* mpi){ pic = av_frame_alloc(); avctx->width = mpi->w; avctx->height = mpi->h; + pic->width = mpi->w; + pic->height = mpi->h; + pic->format = imgfmt2pixfmt(png_format); pic->data[0] = mpi->planes[0]; pic->linesize[0] = mpi->stride[0]; buffersize = mpi->w * mpi->h * 8; -- 1.7.9.5
On 7/15/15, Michael Niedermayer <michaelni@gmx.at> wrote:
From: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libvo/vo_png.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/libvo/vo_png.c b/libvo/vo_png.c index 109ff4f..38a4097 100644 --- a/libvo/vo_png.c +++ b/libvo/vo_png.c @@ -167,6 +167,9 @@ static uint32_t draw_image(mp_image_t* mpi){ pic = av_frame_alloc(); avctx->width = mpi->w; avctx->height = mpi->h; + pic->width = mpi->w; + pic->height = mpi->h; + pic->format = imgfmt2pixfmt(png_format); pic->data[0] = mpi->planes[0]; pic->linesize[0] = mpi->stride[0]; buffersize = mpi->w * mpi->h * 8; -- 1.7.9.5
This patch has been committed in r37428.
On Wed, Jul 15, 2015 at 04:56:28PM +0200, Michael Niedermayer wrote:
From: Michael Niedermayer <michael@niedermayer.cc>
The previous code used uninitialized memory and could randomly crash
The code might be older than av_frame_alloc :) But patches look fine to me.
On Wed, Jul 15, 2015 at 09:25:24PM +0200, Reimar Döffinger wrote:
On Wed, Jul 15, 2015 at 04:56:28PM +0200, Michael Niedermayer wrote:
From: Michael Niedermayer <michael@niedermayer.cc>
The previous code used uninitialized memory and could randomly crash
The code might be older than av_frame_alloc :)
yes, quite likely
But patches look fine to me.
applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Old school: Use the lowest level language in which you can solve the problem conveniently. New school: Use the highest level language in which the latest supercomputer can solve the problem without the user falling asleep waiting.
participants (3)
-
Ivan Kalvachev -
Michael Niedermayer -
Reimar Döffinger