diff mbox

[FFmpeg-devel] dcaenc: fix segfault when attempting to encode with invalid samplerate

Message ID 20180505174334.2408-1-atomnuker@gmail.com
State Accepted
Commit c1b282dc74d801f943db282e89f7729e90897669
Headers show

Commit Message

Rostislav Pehlivanov May 5, 2018, 5:43 p.m. UTC
---
 libavcodec/dcaenc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Paul B Mahol May 5, 2018, 5:59 p.m. UTC | #1
On 5/5/18, Rostislav Pehlivanov <atomnuker@gmail.com> wrote:
> ---
>  libavcodec/dcaenc.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
> index 186997c631..4b4ceeff05 100644
> --- a/libavcodec/dcaenc.c
> +++ b/libavcodec/dcaenc.c
> @@ -152,8 +152,11 @@ static int subband_bufer_alloc(DCAEncContext *c)
>
>  static void subband_bufer_free(DCAEncContext *c)
>  {
> -    int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
> -    av_freep(&bufer);
> +    if (c->subband[0][0]) {
> +        int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
> +        av_free(bufer);
> +        c->subband[0][0] = NULL;
> +    }
>  }
>
>  static int encode_init(AVCodecContext *avctx)

LGTM
Michael Niedermayer May 6, 2018, 12:27 a.m. UTC | #2
On Sat, May 05, 2018 at 06:43:34PM +0100, Rostislav Pehlivanov wrote:
> ---
>  libavcodec/dcaenc.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
> index 186997c631..4b4ceeff05 100644
> --- a/libavcodec/dcaenc.c
> +++ b/libavcodec/dcaenc.c
> @@ -152,8 +152,11 @@ static int subband_bufer_alloc(DCAEncContext *c)
>  
>  static void subband_bufer_free(DCAEncContext *c)
>  {
> -    int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
> -    av_freep(&bufer);
> +    if (c->subband[0][0]) {
> +        int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
> +        av_free(bufer);
> +        c->subband[0][0] = NULL;
> +    }

LGTM but adding a seperate field representing the allocated array
that isnt offset could be clearer and more robust.

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 186997c631..4b4ceeff05 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -152,8 +152,11 @@  static int subband_bufer_alloc(DCAEncContext *c)
 
 static void subband_bufer_free(DCAEncContext *c)
 {
-    int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
-    av_freep(&bufer);
+    if (c->subband[0][0]) {
+        int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
+        av_free(bufer);
+        c->subband[0][0] = NULL;
+    }
 }
 
 static int encode_init(AVCodecContext *avctx)