avcodec/frame_thread_encoder: Free AVCodecContext structure on error during init
Fixes: MemLeak Fixes: 8281 Fixes: PoC_option158.jpg Fixes: CVE-2020-22037 Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
318e184022
commit
7bba0dd638
|
@ -126,7 +126,7 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
ThreadContext *c;
|
ThreadContext *c;
|
||||||
|
AVCodecContext *thread_avctx = NULL;
|
||||||
|
|
||||||
if( !(avctx->thread_type & FF_THREAD_FRAME)
|
if( !(avctx->thread_type & FF_THREAD_FRAME)
|
||||||
|| !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
|
|| !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
|
||||||
|
@ -202,16 +202,17 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx)
|
||||||
for(i=0; i<avctx->thread_count ; i++){
|
for(i=0; i<avctx->thread_count ; i++){
|
||||||
int ret;
|
int ret;
|
||||||
void *tmpv;
|
void *tmpv;
|
||||||
AVCodecContext *thread_avctx = avcodec_alloc_context3(avctx->codec);
|
thread_avctx = avcodec_alloc_context3(avctx->codec);
|
||||||
if(!thread_avctx)
|
if(!thread_avctx)
|
||||||
goto fail;
|
goto fail;
|
||||||
tmpv = thread_avctx->priv_data;
|
tmpv = thread_avctx->priv_data;
|
||||||
*thread_avctx = *avctx;
|
*thread_avctx = *avctx;
|
||||||
|
thread_avctx->priv_data = tmpv;
|
||||||
|
thread_avctx->internal = NULL;
|
||||||
|
thread_avctx->hw_frames_ctx = NULL;
|
||||||
ret = av_opt_copy(thread_avctx, avctx);
|
ret = av_opt_copy(thread_avctx, avctx);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
thread_avctx->priv_data = tmpv;
|
|
||||||
thread_avctx->internal = NULL;
|
|
||||||
if (avctx->codec->priv_class) {
|
if (avctx->codec->priv_class) {
|
||||||
int ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data);
|
int ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -233,6 +234,8 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
fail:
|
||||||
|
avcodec_close(thread_avctx);
|
||||||
|
av_freep(&thread_avctx);
|
||||||
avctx->thread_count = i;
|
avctx->thread_count = i;
|
||||||
av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");
|
av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");
|
||||||
ff_frame_thread_encoder_free(avctx);
|
ff_frame_thread_encoder_free(avctx);
|
||||||
|
|
|
@ -23,6 +23,10 @@
|
||||||
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize frame thread encoder.
|
||||||
|
* @note hardware encoders are not supported
|
||||||
|
*/
|
||||||
int ff_frame_thread_encoder_init(AVCodecContext *avctx);
|
int ff_frame_thread_encoder_init(AVCodecContext *avctx);
|
||||||
void ff_frame_thread_encoder_free(AVCodecContext *avctx);
|
void ff_frame_thread_encoder_free(AVCodecContext *avctx);
|
||||||
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||||
|
|
Loading…
Reference in New Issue