diff mbox

[FFmpeg-devel,2/3] avutil/tests/audio_fifo.c: Memory leak and tab space fixes

Message ID 1482893000-29962-2-git-send-email-thomastdt@googlemail.com
State Accepted
Commit 1bfb4587a2e5b25ed15f742149e555efc8f305ae
Headers show

Commit Message

Thomas Turner Dec. 28, 2016, 2:43 a.m. UTC
Prevents memory leak when read_samples_from_audio_fifo() is
called more than once by deallocating before reallocating
more memory.

Fixes space indentation for contents in ERROR().

Signed-off-by: Thomas Turner <thomastdt@googlemail.com>
---
 libavutil/tests/audio_fifo.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Michael Niedermayer Dec. 31, 2016, 4:18 p.m. UTC | #1
On Tue, Dec 27, 2016 at 06:43:19PM -0800, Thomas Turner wrote:
> Prevents memory leak when read_samples_from_audio_fifo() is
> called more than once by deallocating before reallocating
> more memory.
> 
> Fixes space indentation for contents in ERROR().
> 
> Signed-off-by: Thomas Turner <thomastdt@googlemail.com>
> ---
>  libavutil/tests/audio_fifo.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)

applied

thx

[...]
diff mbox

Patch

diff --git a/libavutil/tests/audio_fifo.c b/libavutil/tests/audio_fifo.c
index 9dc6054..2cef6f0 100644
--- a/libavutil/tests/audio_fifo.c
+++ b/libavutil/tests/audio_fifo.c
@@ -45,10 +45,19 @@  static const TestStruct test_struct[] = {
     {.format = AV_SAMPLE_FMT_FLTP , .nb_ch = 2, .data_planes = {data_FLT, data_FLT+6, }, .nb_samples_pch = 6 }
 };
 
+static void free_data_planes(AVAudioFifo *afifo, void **output_data)
+{
+    int i;
+    for (i = 0; i < afifo->nb_buffers; ++i){
+        av_freep(&output_data[i]);
+    }
+    av_freep(&output_data);
+}
+
 static void ERROR(const char *str)
 {
-        fprintf(stderr, "%s\n", str);
-        exit(1);
+    fprintf(stderr, "%s\n", str);
+    exit(1);
 }
 
 static void print_audio_bytes(const TestStruct *test_sample, void **data_planes, int nb_samples)
@@ -80,6 +89,8 @@  static int read_samples_from_audio_fifo(AVAudioFifo* afifo, void ***output, int
     void **data_planes = av_malloc_array(afifo->nb_buffers, sizeof(void*));
     if (!data_planes)
         ERROR("failed to allocate memory!");
+    if (*output)
+        free_data_planes(afifo, *output);
     *output            = data_planes;
 
     for (i = 0; i < afifo->nb_buffers; ++i){
@@ -173,10 +184,7 @@  static void test_function(const TestStruct test_sample)
     }
 
     /* deallocate */
-    for (i = 0; i < afifo->nb_buffers; ++i){
-        av_freep(&output_data[i]);
-    }
-    av_freep(&output_data);
+    free_data_planes(afifo, output_data);
     av_audio_fifo_free(afifo);
 }