diff mbox series

[FFmpeg-devel] avutil/dict: Deduplicate freeing dictionary

Message ID AS8P250MB07445DA3F5B79238A6312E5C8F222@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit dfffe037555f3564a22e5f456d93a858bf7e3588
Headers show
Series [FFmpeg-devel] avutil/dict: Deduplicate freeing dictionary | 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 March 5, 2024, 3:53 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/dict.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Andreas Rheinhardt March 7, 2024, 8:13 a.m. UTC | #1
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavutil/dict.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index 7f23d5336a..6fb09399ba 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -145,11 +145,8 @@ 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);
> +        err = 0;
> +        goto end;
>      }
>  
>      return 0;
> @@ -157,12 +154,13 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
>  enomem:
>      err = AVERROR(ENOMEM);
>  err_out:
> +    av_free(copy_value);
> +end:
>      if (m && !m->count) {
>          av_freep(&m->elems);
>          av_freep(pm);
>      }
>      av_free(copy_key);
> -    av_free(copy_value);
>      return err;
>  }
>  

Will apply this patch tomorrow unless there are objections.

- Andreas
Marvin Scholz March 7, 2024, 9:47 a.m. UTC | #2
On 5 Mar 2024, at 16:53, Andreas Rheinhardt wrote:

> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavutil/dict.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index 7f23d5336a..6fb09399ba 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -145,11 +145,8 @@ 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);
> +        err = 0;
> +        goto end;
>      }
>
>      return 0;
> @@ -157,12 +154,13 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
>  enomem:
>      err = AVERROR(ENOMEM);
>  err_out:
> +    av_free(copy_value);
> +end:
>      if (m && !m->count) {
>          av_freep(&m->elems);
>          av_freep(pm);
>      }
>      av_free(copy_key);
> -    av_free(copy_value);
>      return err;
>  }
>
> -- 
> 2.40.1

LGTM

>
> _______________________________________________
> 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 7f23d5336a..6fb09399ba 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -145,11 +145,8 @@  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);
+        err = 0;
+        goto end;
     }
 
     return 0;
@@ -157,12 +154,13 @@  int av_dict_set(AVDictionary **pm, const char *key, const char *value,
 enomem:
     err = AVERROR(ENOMEM);
 err_out:
+    av_free(copy_value);
+end:
     if (m && !m->count) {
         av_freep(&m->elems);
         av_freep(pm);
     }
     av_free(copy_key);
-    av_free(copy_value);
     return err;
 }