diff mbox series

[FFmpeg-devel,6/9] avformat/smacker: Don't allocate arrays separately

Message ID 20200624134705.14833-6-andreas.rheinhardt@gmail.com
State Accepted
Commit 09a39042db1b34672ba92a29c2b2f8f18a588a40
Headers show
Series [FFmpeg-devel,1/9] avformat/smacker: Don't increase packet counter prematurely
Related show

Checks

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

Commit Message

Andreas Rheinhardt June 24, 2020, 1:47 p.m. UTC
Allocating two arrays with the same number of elements together
simplifies freeing them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/smacker.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 0138af3d14..2043563fdb 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -205,13 +205,11 @@  static int smacker_read_header(AVFormatContext *s)
     avio_rl32(pb); /* padding */
 
     /* setup data */
-    smk->frm_size  = av_malloc_array(smk->frames, sizeof(*smk->frm_size));
-    smk->frm_flags = av_malloc(smk->frames);
-    if (!smk->frm_size || !smk->frm_flags) {
-        av_freep(&smk->frm_size);
-        av_freep(&smk->frm_flags);
+    smk->frm_size  = av_malloc_array(smk->frames, sizeof(*smk->frm_size) +
+                                                  sizeof(*smk->frm_flags));
+    if (!smk->frm_size)
         return AVERROR(ENOMEM);
-    }
+    smk->frm_flags = (void*)(smk->frm_size + smk->frames);
 
     /* read frame info */
     for (i = 0; i < smk->frames; i++) {
@@ -225,7 +223,6 @@  static int smacker_read_header(AVFormatContext *s)
     ret = avio_read(pb, par->extradata + 16, par->extradata_size - 16);
     if (ret != par->extradata_size - 16) {
         av_freep(&smk->frm_size);
-        av_freep(&smk->frm_flags);
         return AVERROR(EIO);
     }
 
@@ -362,7 +359,6 @@  static int smacker_read_close(AVFormatContext *s)
     SmackerContext *smk = s->priv_data;
 
     av_freep(&smk->frm_size);
-    av_freep(&smk->frm_flags);
 
     return 0;
 }