diff mbox series

[FFmpeg-devel,19/25] avcodec/utils: Remove always-true check

Message ID 20200926102804.228089-19-andreas.rheinhardt@gmail.com
State Accepted
Commit 502c5fe10143247b0566d3d2bb927f49769c2181
Headers show
Series [FFmpeg-devel,01/25] avcodec/photocd: Simplify parsing Huffman tables a bit | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 26, 2020, 10:27 a.m. UTC
The first thing avcodec_open2() allocates is the AVCodecInternal. If
allocating it fails, a jump to end occurs; but if an error happens after
its allocation, a jump to free_and_end happens which frees all
allocations performed so far and then jumps to end. Yet free_and_end
contained a check for AVCodecInternal (after having already dereferenced
it to check whether ff_thread_free() needs to be called) which is of
course always true. So remove it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/utils.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Andreas Rheinhardt Sept. 30, 2020, 11:14 a.m. UTC | #1
Andreas Rheinhardt:
> The first thing avcodec_open2() allocates is the AVCodecInternal. If
> allocating it fails, a jump to end occurs; but if an error happens after
> its allocation, a jump to free_and_end happens which frees all
> allocations performed so far and then jumps to end. Yet free_and_end
> contained a check for AVCodecInternal (after having already dereferenced
> it to check whether ff_thread_free() needs to be called) which is of
> course always true. So remove it.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/utils.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 94b9e94584..8e7c3125aa 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1043,7 +1043,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      av_dict_free(&tmp);
>      av_freep(&avctx->priv_data);
>      av_freep(&avctx->subtitle_header);
> -    if (avci) {
> +
>          av_frame_free(&avci->to_free);
>          av_frame_free(&avci->compat_decode_frame);
>          av_frame_free(&avci->buffer_frame);
> @@ -1056,7 +1056,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          av_bsf_free(&avci->bsf);
>  
>          av_buffer_unref(&avci->pool);
> -    }
>      av_freep(&avci);
>      avctx->internal = NULL;
>      avctx->codec = NULL;
> 
Will apply the rest of this patchset this evening unless there are
objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 94b9e94584..8e7c3125aa 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1043,7 +1043,7 @@  FF_ENABLE_DEPRECATION_WARNINGS
     av_dict_free(&tmp);
     av_freep(&avctx->priv_data);
     av_freep(&avctx->subtitle_header);
-    if (avci) {
+
         av_frame_free(&avci->to_free);
         av_frame_free(&avci->compat_decode_frame);
         av_frame_free(&avci->buffer_frame);
@@ -1056,7 +1056,6 @@  FF_ENABLE_DEPRECATION_WARNINGS
         av_bsf_free(&avci->bsf);
 
         av_buffer_unref(&avci->pool);
-    }
     av_freep(&avci);
     avctx->internal = NULL;
     avctx->codec = NULL;