diff mbox series

[FFmpeg-devel,V1,02/12] lavc/libkvazaar: fix memory leak after av_dict_parse_string fail

Message ID 1577856040-17409-2-git-send-email-mypopydev@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,V1,01/12] lavc/bsf: fix memory leak after av_dict_parse_string fail | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Jun Zhao Jan. 1, 2020, 5:20 a.m. UTC
From: Jun Zhao <barryjzhao@tencent.com>

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavcodec/libkvazaar.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

James Almer Jan. 1, 2020, 5:24 a.m. UTC | #1
On 1/1/2020 2:20 AM, Jun Zhao wrote:
> From: Jun Zhao <barryjzhao@tencent.com>
> 
> In case of failure, all the successfully set entries are stored in
> *pm. We need to manually free the created dictionary to avoid
> memory leak.
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>  libavcodec/libkvazaar.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
> index a89ca7f..02bcae3 100644
> --- a/libavcodec/libkvazaar.c
> +++ b/libavcodec/libkvazaar.c
> @@ -110,8 +110,8 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
>                             entry->key, entry->value);
>                  }
>              }
> -            av_dict_free(&dict);
>          }
> +        av_dict_free(&dict);
>      }
>  
>      ctx->encoder = enc = api->encoder_open(cfg);

There's a patchset by Marton Balint changing this code in all the same
modules as in this patchset, by replacing it all with a simple
av_dict_copy() call.

http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254805.html
and every following patch.
Marton Balint Jan. 1, 2020, 4:46 p.m. UTC | #2
On Wed, 1 Jan 2020, James Almer wrote:

> On 1/1/2020 2:20 AM, Jun Zhao wrote:
>> From: Jun Zhao <barryjzhao@tencent.com>
>> 
>> In case of failure, all the successfully set entries are stored in
>> *pm. We need to manually free the created dictionary to avoid
>> memory leak.
>> 
>> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
>> ---
>>  libavcodec/libkvazaar.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>> 
>> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
>> index a89ca7f..02bcae3 100644
>> --- a/libavcodec/libkvazaar.c
>> +++ b/libavcodec/libkvazaar.c
>> @@ -110,8 +110,8 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
>>                             entry->key, entry->value);
>>                  }
>>              }
>> -            av_dict_free(&dict);
>>          }
>> +        av_dict_free(&dict);
>>      }
>>
>>      ctx->encoder = enc = api->encoder_open(cfg);
>
> There's a patchset by Marton Balint changing this code in all the same
> modules as in this patchset, by replacing it all with a simple
> av_dict_copy() call.
>
> http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254805.html
> and every following patch.

Yeah, although not every patch is covered, because libkvazaar for example 
uses comma(,) separator instead of colon(:) spearator, so it could not be 
converted to a simple AV_OPT_TYPE_DICT.

Probably I should apply my pending patches and then you should rebase this 
series and keep the ones which are still relevant.

Thanks,
Marton
mypopy@gmail.com Jan. 2, 2020, 1:22 a.m. UTC | #3
On Thu, Jan 2, 2020 at 12:46 AM Marton Balint <cus@passwd.hu> wrote:
>
>
>
> On Wed, 1 Jan 2020, James Almer wrote:
>
> > On 1/1/2020 2:20 AM, Jun Zhao wrote:
> >> From: Jun Zhao <barryjzhao@tencent.com>
> >>
> >> In case of failure, all the successfully set entries are stored in
> >> *pm. We need to manually free the created dictionary to avoid
> >> memory leak.
> >>
> >> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> >> ---
> >>  libavcodec/libkvazaar.c |    2 +-
> >>  1 files changed, 1 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
> >> index a89ca7f..02bcae3 100644
> >> --- a/libavcodec/libkvazaar.c
> >> +++ b/libavcodec/libkvazaar.c
> >> @@ -110,8 +110,8 @@ static av_cold int libkvazaar_init(AVCodecContext
*avctx)
> >>                             entry->key, entry->value);
> >>                  }
> >>              }
> >> -            av_dict_free(&dict);
> >>          }
> >> +        av_dict_free(&dict);
> >>      }
> >>
> >>      ctx->encoder = enc = api->encoder_open(cfg);
> >
> > There's a patchset by Marton Balint changing this code in all the same
> > modules as in this patchset, by replacing it all with a simple
> > av_dict_copy() call.
> >
> > http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-December/254805.html
> > and every following patch.
>
> Yeah, although not every patch is covered, because libkvazaar for example
> uses comma(,) separator instead of colon(:) spearator, so it could not be
> converted to a simple AV_OPT_TYPE_DICT.
>
> Probably I should apply my pending patches and then you should rebase this
> series and keep the ones which are still relevant.
>
Ok, I will rebase the patchset after you apply the pending AV_OPT_TYPE_DICT
patches.
diff mbox series

Patch

diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index a89ca7f..02bcae3 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -110,8 +110,8 @@  static av_cold int libkvazaar_init(AVCodecContext *avctx)
                            entry->key, entry->value);
                 }
             }
-            av_dict_free(&dict);
         }
+        av_dict_free(&dict);
     }
 
     ctx->encoder = enc = api->encoder_open(cfg);