Message ID | 20210216222920.3078696-1-wonkap@google.com |
---|---|
State | Superseded |
Headers | show |
Series | [FFmpeg-devel,v2] avcodec/libvpxenc: fix potential memory leak. | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
On Tue, Feb 16, 2021 at 2:29 PM Wonkap Jang <wonkap-at-google.com@ffmpeg.org> wrote: > > While parsing ref_frame_config, AVdictionary needs to be manually > deallocated. > --- > libavcodec/libvpxenc.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 deletions(-) > > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c > index 284cb9a108..e71ae54f34 100644 > --- a/libavcodec/libvpxenc.c > +++ b/libavcodec/libvpxenc.c > @@ -1595,15 +1595,21 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, > if (en) { > if (avctx->codec_id == AV_CODEC_ID_VP9) { > AVDictionaryEntry* en2 = NULL; > - av_dict_parse_string(&ctx->vpx_ref_frame_config, en->value, "=", ":", 0); > - > - while ((en2 = av_dict_get(ctx->vpx_ref_frame_config, "", en2, AV_DICT_IGNORE_SUFFIX))) { > - if (vpx_ref_frame_config_parse(ctx, enccfg, en2->key, en2->value, avctx->codec_id) < 0) > - av_log(avctx, AV_LOG_WARNING, > - "Error parsing option '%s = %s'.\n", > - en2->key, en2->value); > + ctx->vpx_ref_frame_config = NULL; > + if (av_dict_parse_string(&ctx->vpx_ref_frame_config, en->value, "=", ":", 0) == 0) { ! is preferred to testing 0.
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 284cb9a108..e71ae54f34 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -1595,15 +1595,21 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, if (en) { if (avctx->codec_id == AV_CODEC_ID_VP9) { AVDictionaryEntry* en2 = NULL; - av_dict_parse_string(&ctx->vpx_ref_frame_config, en->value, "=", ":", 0); - - while ((en2 = av_dict_get(ctx->vpx_ref_frame_config, "", en2, AV_DICT_IGNORE_SUFFIX))) { - if (vpx_ref_frame_config_parse(ctx, enccfg, en2->key, en2->value, avctx->codec_id) < 0) - av_log(avctx, AV_LOG_WARNING, - "Error parsing option '%s = %s'.\n", - en2->key, en2->value); + ctx->vpx_ref_frame_config = NULL; + if (av_dict_parse_string(&ctx->vpx_ref_frame_config, en->value, "=", ":", 0) == 0) { + while ((en2 = av_dict_get(ctx->vpx_ref_frame_config, "", en2, AV_DICT_IGNORE_SUFFIX))) { + if (vpx_ref_frame_config_parse(ctx, enccfg, en2->key, en2->value, avctx->codec_id) < 0) + av_log(avctx, AV_LOG_WARNING, + "Error parsing option '%s = %s'.\n", + en2->key, en2->value); + } + } else { + av_log(avctx, AV_LOG_WARNING, + "Error in parsing ref-frame-config. \n"); } + if (ctx->vpx_ref_frame_config) + av_dict_free(&ctx->vpx_ref_frame_config); codecctl_intp(avctx, VP9E_SET_SVC_REF_FRAME_CONFIG, (int *)&ctx->ref_frame_config); } else { av_log(avctx, AV_LOG_WARNING,