[FFmpeg-devel] [PATCH v3] avcodec/libvpxenc: fix potential memory leak.
Nicolas George
george at nsup.org
Wed Feb 17 19:50:16 EET 2021
Wonkap Jang (12021-02-17):
> While parsing ref_frame_config, AVdictionary needs to be manually
> deallocated.
> ---
> libavcodec/libvpxenc.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 284cb9a108..56a1b5aafe 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -127,7 +127,6 @@ typedef struct VPxEncoderContext {
> int roi_warned;
> #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
> vpx_svc_ref_frame_config_t ref_frame_config;
> - AVDictionary *vpx_ref_frame_config;
> #endif
> } VPxContext;
>
> @@ -1595,15 +1594,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);
> + AVDictionary* vpx_ref_frame_config = NULL;
> +
> + if (av_dict_parse_string(&vpx_ref_frame_config, en->value, "=", ":", 0) != 0) {
> + av_log(avctx, AV_LOG_WARNING,
> + "Error in parsing ref-frame-config. \n");
I forgot this the first time: the error must be forwarded.
> + } else {
> + while ((en2 = av_dict_get(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);
> + }
See my other mail: it should not be in a dictionary at all, just passing
the string and using the values immediately.
> }
>
> + av_dict_free(&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,
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210217/62c86349/attachment.sig>
More information about the ffmpeg-devel
mailing list