diff mbox

[FFmpeg-devel] avformat/id3v2: Avoid av_strdup for key and value of dict

Message ID 20191110180451.31708-1-andreas.rheinhardt@gmail.com
State Accepted
Commit a7245adee3e98d4b2e2a1bb7ddc0caae898b5193
Headers show

Commit Message

Andreas Rheinhardt Nov. 10, 2019, 6:04 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/id3v2.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Paul B Mahol Nov. 13, 2019, 3:46 p.m. UTC | #1
lgtm

On 11/10/19, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/id3v2.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
> index e9843eef9a..abe073dcc1 100644
> --- a/libavformat/id3v2.c
> +++ b/libavformat/id3v2.c
> @@ -361,8 +361,8 @@ static void read_uslt(AVFormatContext *s, AVIOContext
> *pb, int taglen,
>  {
>      uint8_t lang[4];
>      uint8_t *descriptor = NULL; // 'Content descriptor'
> -    uint8_t *text = NULL;
> -    char *key = NULL;
> +    uint8_t *text;
> +    char *key;
>      int encoding;
>      int ok = 0;
>
> @@ -387,18 +387,19 @@ static void read_uslt(AVFormatContext *s, AVIOContext
> *pb, int taglen,
>      key = av_asprintf("lyrics-%s%s%s", descriptor[0] ? (char *)descriptor :
> "",
>                                         descriptor[0] ? "-" : "",
>                                         lang);
> -    if (!key)
> +    if (!key) {
> +        av_free(text);
>          goto error;
> +    }
>
> -    av_dict_set(metadata, key, text, 0);
> +    av_dict_set(metadata, key, text,
> +                AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
>
>      ok = 1;
>  error:
>      if (!ok)
>          av_log(s, AV_LOG_ERROR, "Error reading lyrics, skipped\n");
>      av_free(descriptor);
> -    av_free(text);
> -    av_free(key);
>  }
>
>  /**
> --
> 2.20.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".
Michael Niedermayer Nov. 13, 2019, 10:39 p.m. UTC | #2
On Wed, Nov 13, 2019 at 04:46:48PM +0100, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index e9843eef9a..abe073dcc1 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -361,8 +361,8 @@  static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen,
 {
     uint8_t lang[4];
     uint8_t *descriptor = NULL; // 'Content descriptor'
-    uint8_t *text = NULL;
-    char *key = NULL;
+    uint8_t *text;
+    char *key;
     int encoding;
     int ok = 0;
 
@@ -387,18 +387,19 @@  static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen,
     key = av_asprintf("lyrics-%s%s%s", descriptor[0] ? (char *)descriptor : "",
                                        descriptor[0] ? "-" : "",
                                        lang);
-    if (!key)
+    if (!key) {
+        av_free(text);
         goto error;
+    }
 
-    av_dict_set(metadata, key, text, 0);
+    av_dict_set(metadata, key, text,
+                AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
 
     ok = 1;
 error:
     if (!ok)
         av_log(s, AV_LOG_ERROR, "Error reading lyrics, skipped\n");
     av_free(descriptor);
-    av_free(text);
-    av_free(key);
 }
 
 /**