diff mbox series

[FFmpeg-devel,10/54] avformat/av1dec: Simplify cleanup after read_header failure

Message ID HE1PR0301MB2154CEEC4690FFA11DDD0A538F309@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Headers show
Series [FFmpeg-devel,01/54] avformat: Add internal flags for AV(In|Out)putFormat
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt June 15, 2021, 11:31 p.m. UTC
by setting the FF_FMT_INIT_CLEANUP flag.

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

Comments

James Almer June 17, 2021, 2:27 a.m. UTC | #1
On 6/15/2021 8:31 PM, Andreas Rheinhardt wrote:
> by setting the FF_FMT_INIT_CLEANUP flag.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>   libavformat/av1dec.c | 13 ++++---------
>   1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
> index 8ca804c2a3..f282477ca4 100644
> --- a/libavformat/av1dec.c
> +++ b/libavformat/av1dec.c
> @@ -77,17 +77,10 @@ static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFCon
>           return ret;
>   
>       ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
> -    if (ret < 0) {
> -        av_bsf_free(bsf);
> -        return ret;
> -    }
> -
> -    ret = av_bsf_init(*bsf);
>       if (ret < 0)
> -        av_bsf_free(bsf);
> -
> -    return ret;
> +        return ret;
>   
> +    return av_bsf_init(*bsf);

nit: I'd prefer if you keep the two ret < 0 checks with their 
corresponding return rets, and make the last line an explicit return 0 
(For whatever reason, av_bsf_init() doxy does not mention what values it 
returns).

>   }
>   
>   #define DEC AV_OPT_FLAG_DECODING_PARAM
> @@ -285,6 +278,7 @@ const AVInputFormat ff_av1_demuxer = {
>       .name           = "av1",
>       .long_name      = NULL_IF_CONFIG_SMALL("AV1 Annex B"),
>       .priv_data_size = sizeof(AnnexBContext),
> +    .flags_internal = FF_FMT_INIT_CLEANUP,
>       .read_probe     = annexb_probe,
>       .read_header    = annexb_read_header,
>       .read_packet    = annexb_read_packet,
> @@ -472,6 +466,7 @@ const AVInputFormat ff_obu_demuxer = {
>       .name           = "obu",
>       .long_name      = NULL_IF_CONFIG_SMALL("AV1 low overhead OBU"),
>       .priv_data_size = sizeof(ObuContext),
> +    .flags_internal = FF_FMT_INIT_CLEANUP,
>       .read_probe     = obu_probe,
>       .read_header    = obu_read_header,
>       .read_packet    = obu_read_packet,
>
Andreas Rheinhardt July 7, 2021, 5:38 p.m. UTC | #2
James Almer:
> On 6/15/2021 8:31 PM, Andreas Rheinhardt wrote:
>> by setting the FF_FMT_INIT_CLEANUP flag.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>   libavformat/av1dec.c | 13 ++++---------
>>   1 file changed, 4 insertions(+), 9 deletions(-)
>>
>> diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
>> index 8ca804c2a3..f282477ca4 100644
>> --- a/libavformat/av1dec.c
>> +++ b/libavformat/av1dec.c
>> @@ -77,17 +77,10 @@ static int read_header(AVFormatContext *s, const
>> AVRational *framerate, AVBSFCon
>>           return ret;
>>         ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
>> -    if (ret < 0) {
>> -        av_bsf_free(bsf);
>> -        return ret;
>> -    }
>> -
>> -    ret = av_bsf_init(*bsf);
>>       if (ret < 0)
>> -        av_bsf_free(bsf);
>> -
>> -    return ret;
>> +        return ret;
>>   +    return av_bsf_init(*bsf);
> 
> nit: I'd prefer if you keep the two ret < 0 checks with their
> corresponding return rets, and make the last line an explicit return 0
> (For whatever reason, av_bsf_init() doxy does not mention what values it
> returns).
> 

Will apply the patchset with this change.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 8ca804c2a3..f282477ca4 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -77,17 +77,10 @@  static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFCon
         return ret;
 
     ret = avcodec_parameters_copy((*bsf)->par_in, st->codecpar);
-    if (ret < 0) {
-        av_bsf_free(bsf);
-        return ret;
-    }
-
-    ret = av_bsf_init(*bsf);
     if (ret < 0)
-        av_bsf_free(bsf);
-
-    return ret;
+        return ret;
 
+    return av_bsf_init(*bsf);
 }
 
 #define DEC AV_OPT_FLAG_DECODING_PARAM
@@ -285,6 +278,7 @@  const AVInputFormat ff_av1_demuxer = {
     .name           = "av1",
     .long_name      = NULL_IF_CONFIG_SMALL("AV1 Annex B"),
     .priv_data_size = sizeof(AnnexBContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = annexb_probe,
     .read_header    = annexb_read_header,
     .read_packet    = annexb_read_packet,
@@ -472,6 +466,7 @@  const AVInputFormat ff_obu_demuxer = {
     .name           = "obu",
     .long_name      = NULL_IF_CONFIG_SMALL("AV1 low overhead OBU"),
     .priv_data_size = sizeof(ObuContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = obu_probe,
     .read_header    = obu_read_header,
     .read_packet    = obu_read_packet,