diff mbox series

[FFmpeg-devel,2/3] avcodec/fft: Set potentially unused wrapper variables to avoid invalid free/uninit

Message ID 20231112151144.2307049-3-sramacher@debian.org
State New
Headers show
Series Fix invalid frees, segfaults and memory leaks in avcodec/fft wrappers | 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

Sebastian Ramacher Nov. 12, 2023, 3:11 p.m. UTC
---
 libavcodec/avfft.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

James Almer Nov. 12, 2023, 3:17 p.m. UTC | #1
On 11/12/2023 12:11 PM, Sebastian Ramacher wrote:
> ---
>   libavcodec/avfft.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
> index 93203228c2..813b6d61a1 100644
> --- a/libavcodec/avfft.c
> +++ b/libavcodec/avfft.c
> @@ -102,7 +102,8 @@ FFTContext *av_mdct_init(int nbits, int inverse, double scale)
>               av_free(s);
>               return NULL;
>           }
> -    }
> +    } else
> +        s->ctx2 = NULL;
>   
>       return (FFTContext *)s;
>   }
> @@ -220,7 +221,8 @@ DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
>               av_free(s);
>               return NULL;
>           }
> -    }
> +    } else
> +        s->tmp = NULL;
>   
>       return (DCTContext *)s;
>   }

IMO just allocate the AVTXWrapper with av_mallocz() instead.
diff mbox series

Patch

diff --git a/libavcodec/avfft.c b/libavcodec/avfft.c
index 93203228c2..813b6d61a1 100644
--- a/libavcodec/avfft.c
+++ b/libavcodec/avfft.c
@@ -102,7 +102,8 @@  FFTContext *av_mdct_init(int nbits, int inverse, double scale)
             av_free(s);
             return NULL;
         }
-    }
+    } else
+        s->ctx2 = NULL;
 
     return (FFTContext *)s;
 }
@@ -220,7 +221,8 @@  DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
             av_free(s);
             return NULL;
         }
-    }
+    } else
+        s->tmp = NULL;
 
     return (DCTContext *)s;
 }