[FFmpeg-devel,1/3] avutil/tests/audio_fifo.c: use av_malloc() family of functions

Submitted by Thomas Turner on Dec. 28, 2016, 2:43 a.m.

Details

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

Commit Message

Thomas Turner Dec. 28, 2016, 2:43 a.m.
Signed-off-by: James Almer <jamrial@gmail.com>

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

Comments

Michael Niedermayer Dec. 31, 2016, 4:17 p.m.
On Tue, Dec 27, 2016 at 06:43:18PM -0800, Thomas Turner wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>

not sure were that comes from, not really important but
applied without that

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavutil/tests/audio_fifo.c b/libavutil/tests/audio_fifo.c
index 34c8573..9dc6054 100644
--- a/libavutil/tests/audio_fifo.c
+++ b/libavutil/tests/audio_fifo.c
@@ -19,6 +19,7 @@ 
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
+#include "libavutil/mem.h"
 #include "libavutil/audio_fifo.c"
 
 #define MAX_CHANNELS    32
@@ -50,15 +51,6 @@  static void ERROR(const char *str)
         exit(1);
 }
 
-static void* allocate_memory(size_t size)
-{
-    void *ptr = malloc(size);
-    if (ptr == NULL){
-        ERROR("failed to allocate memory!");
-    }
-    return ptr;
-}
-
 static void print_audio_bytes(const TestStruct *test_sample, void **data_planes, int nb_samples)
 {
     int p, b, f;
@@ -85,11 +77,15 @@  static int read_samples_from_audio_fifo(AVAudioFifo* afifo, void ***output, int
     int samples        = FFMIN(nb_samples, afifo->nb_samples);
     int tot_elements   = !av_sample_fmt_is_planar(afifo->sample_fmt)
                          ? samples : afifo->channels * samples;
-    void **data_planes = allocate_memory(sizeof(void*) * afifo->nb_buffers);
+    void **data_planes = av_malloc_array(afifo->nb_buffers, sizeof(void*));
+    if (!data_planes)
+        ERROR("failed to allocate memory!");
     *output            = data_planes;
 
     for (i = 0; i < afifo->nb_buffers; ++i){
-        data_planes[i] = allocate_memory(afifo->sample_size * tot_elements);
+        data_planes[i] = av_malloc_array(tot_elements, afifo->sample_size);
+        if (!data_planes[i])
+            ERROR("failed to allocate memory!");
     }
 
     return av_audio_fifo_read(afifo, *output, nb_samples);
@@ -178,9 +174,9 @@  static void test_function(const TestStruct test_sample)
 
     /* deallocate */
     for (i = 0; i < afifo->nb_buffers; ++i){
-        free(output_data[i]);
+        av_freep(&output_data[i]);
     }
-    free(output_data);
+    av_freep(&output_data);
     av_audio_fifo_free(afifo);
 }