[FFmpeg-cvslog] avcodec/adts_parser: allow passing a pre allocated AACADTSHeaderInfo to avpriv_adts_header_parse()

James Almer git at videolan.org
Wed Oct 26 16:33:55 EEST 2022


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sat Oct 22 22:07:34 2022 -0300| [676e7d7f9b5dc76d5124cc99e3a3fa6c823decc3] | committer: James Almer

avcodec/adts_parser: allow passing a pre allocated AACADTSHeaderInfo to avpriv_adts_header_parse()

Code freeing the struct on failure is kept for backwards compatibility, but
should be removed in the next major bump, and the existing lavf user adapted.

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

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=676e7d7f9b5dc76d5124cc99e3a3fa6c823decc3
---

 libavcodec/adts_header.c |  2 ++
 libavcodec/adts_parser.c | 12 +++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavcodec/adts_header.c b/libavcodec/adts_header.c
index ff4efafbf7..00fa0a5a99 100644
--- a/libavcodec/adts_header.c
+++ b/libavcodec/adts_header.c
@@ -32,6 +32,8 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
     int size, rdb, ch, sr;
     int aot, crc_abs;
 
+    memset(hdr, 0, sizeof(*hdr));
+
     if (get_bits(gbc, 12) != 0xfff)
         return AAC_AC3_PARSE_ERROR_SYNC;
 
diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c
index 4a1a8fd5f4..f2e155fc99 100644
--- a/libavcodec/adts_parser.c
+++ b/libavcodec/adts_parser.c
@@ -47,24 +47,30 @@ int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_
 {
 #if CONFIG_ADTS_HEADER
     int ret = 0;
+    int allocated = 0;
     GetBitContext gb;
 
     if (!phdr || !buf || size < AV_AAC_ADTS_HEADER_SIZE)
         return AVERROR_INVALIDDATA;
 
-    *phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
+    if (!*phdr) {
+        allocated = 1;
+        *phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
+    }
     if (!*phdr)
         return AVERROR(ENOMEM);
 
     ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
     if (ret < 0) {
-        av_freep(phdr);
+        if (allocated)
+            av_freep(phdr);
         return ret;
     }
 
     ret = ff_adts_header_parse(&gb, *phdr);
     if (ret < 0) {
-        av_freep(phdr);
+        if (allocated)
+            av_freep(phdr);
         return ret;
     }
 



More information about the ffmpeg-cvslog mailing list