diff mbox series

[FFmpeg-devel,3/3] avutil/dict: Avoid check whose result is known in advance

Message ID GV1P250MB07376CB29C883B97C93CDC4E8F479@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Headers show
Series [FFmpeg-devel,1/3] avutil/dict: Fix memleak when using AV_DICT_APPEND | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 13, 2022, 7:46 p.m. UTC
We know that an AVDictionary is not empty if we have just added
an entry to it, so only check for it being empty on the branch
that does not do so.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/dict.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Paul B Mahol Sept. 13, 2022, 7:51 p.m. UTC | #1
On 9/13/22, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
> We know that an AVDictionary is not empty if we have just added
> an entry to it, so only check for it being empty on the branch
> that does not do so.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavutil/dict.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>

LGTM

> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index 1968063b0b..4bba041d0a 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -123,12 +123,12 @@ int av_dict_set(AVDictionary **pm, const char *key,
> const char *value,
>          m->elems[m->count].value = copy_value;
>          m->count++;
>      } else {
> +        if (!m->count) {
> +            av_freep(&m->elems);
> +            av_freep(pm);
> +        }
>          av_freep(&copy_key);
>      }
> -    if (!m->count) {
> -        av_freep(&m->elems);
> -        av_freep(pm);
> -    }
>
>      return 0;
>
> --
> 2.34.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
diff mbox series

Patch

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 1968063b0b..4bba041d0a 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -123,12 +123,12 @@  int av_dict_set(AVDictionary **pm, const char *key, const char *value,
         m->elems[m->count].value = copy_value;
         m->count++;
     } else {
+        if (!m->count) {
+            av_freep(&m->elems);
+            av_freep(pm);
+        }
         av_freep(&copy_key);
     }
-    if (!m->count) {
-        av_freep(&m->elems);
-        av_freep(pm);
-    }
 
     return 0;