diff mbox

[FFmpeg-devel,1/7] avformat/dss: Use AV_DICT_DONT_STRDUP_VAL to save a malloc+memcpy

Message ID 20191110035406.11500-1-andreas.rheinhardt@gmail.com
State Accepted
Headers show

Commit Message

Andreas Rheinhardt Nov. 10, 2019, 3:54 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/dss.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Andreas Rheinhardt Nov. 18, 2019, 8:47 a.m. UTC | #1
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/dss.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/dss.c b/libavformat/dss.c
> index d7f9cafe47..8bc6af134e 100644
> --- a/libavformat/dss.c
> +++ b/libavformat/dss.c
> @@ -103,15 +103,11 @@ static int dss_read_metadata_string(AVFormatContext *s, unsigned int offset,
>  
>      ret = avio_read(s->pb, value, size);
>      if (ret < size) {
> -        ret = ret < 0 ? ret : AVERROR_EOF;
> -        goto exit;
> +        av_free(value);
> +        return ret < 0 ? ret : AVERROR_EOF;
>      }
>  
> -    ret = av_dict_set(&s->metadata, key, value, 0);
> -
> -exit:
> -    av_free(value);
> -    return ret;
> +    return av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
>  }
>  
>  static int dss_read_header(AVFormatContext *s)
> 

Ping.

- Andreas
Paul B Mahol Nov. 18, 2019, 9:25 a.m. UTC | #2
lgtm

On 11/10/19, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/dss.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/libavformat/dss.c b/libavformat/dss.c
> index d7f9cafe47..8bc6af134e 100644
> --- a/libavformat/dss.c
> +++ b/libavformat/dss.c
> @@ -103,15 +103,11 @@ static int dss_read_metadata_string(AVFormatContext
> *s, unsigned int offset,
>
>      ret = avio_read(s->pb, value, size);
>      if (ret < size) {
> -        ret = ret < 0 ? ret : AVERROR_EOF;
> -        goto exit;
> +        av_free(value);
> +        return ret < 0 ? ret : AVERROR_EOF;
>      }
>
> -    ret = av_dict_set(&s->metadata, key, value, 0);
> -
> -exit:
> -    av_free(value);
> -    return ret;
> +    return av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
>  }
>
>  static int dss_read_header(AVFormatContext *s)
> --
> 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".
Andreas Rheinhardt March 24, 2020, 10:07 p.m. UTC | #3
Paul B Mahol:
> lgtm
> 
> On 11/10/19, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
>> ---
>>  libavformat/dss.c | 10 +++-------
>>  1 file changed, 3 insertions(+), 7 deletions(-)
>>
>> diff --git a/libavformat/dss.c b/libavformat/dss.c
>> index d7f9cafe47..8bc6af134e 100644
>> --- a/libavformat/dss.c
>> +++ b/libavformat/dss.c
>> @@ -103,15 +103,11 @@ static int dss_read_metadata_string(AVFormatContext
>> *s, unsigned int offset,
>>
>>      ret = avio_read(s->pb, value, size);
>>      if (ret < size) {
>> -        ret = ret < 0 ? ret : AVERROR_EOF;
>> -        goto exit;
>> +        av_free(value);
>> +        return ret < 0 ? ret : AVERROR_EOF;
>>      }
>>
>> -    ret = av_dict_set(&s->metadata, key, value, 0);
>> -
>> -exit:
>> -    av_free(value);
>> -    return ret;
>> +    return av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
>>  }
>>
>>  static int dss_read_header(AVFormatContext *s)
>> --
>> 2.20.1
>>
Applied, thanks.

- Andreas
diff mbox

Patch

diff --git a/libavformat/dss.c b/libavformat/dss.c
index d7f9cafe47..8bc6af134e 100644
--- a/libavformat/dss.c
+++ b/libavformat/dss.c
@@ -103,15 +103,11 @@  static int dss_read_metadata_string(AVFormatContext *s, unsigned int offset,
 
     ret = avio_read(s->pb, value, size);
     if (ret < size) {
-        ret = ret < 0 ? ret : AVERROR_EOF;
-        goto exit;
+        av_free(value);
+        return ret < 0 ? ret : AVERROR_EOF;
     }
 
-    ret = av_dict_set(&s->metadata, key, value, 0);
-
-exit:
-    av_free(value);
-    return ret;
+    return av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL);
 }
 
 static int dss_read_header(AVFormatContext *s)