]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/flac_parser: Don't allocate array separately
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 6 Oct 2019 05:01:14 +0000 (07:01 +0200)
committerPaul B Mahol <onemda@gmail.com>
Mon, 7 Oct 2019 20:27:18 +0000 (22:27 +0200)
The FLACHeaderMarker structure contained a pointer to an array of int;
said array was always allocated and freed at the same time as its
referencing FLACHeaderMarker; the pointer was never modified to point to
a different array and each FLACHeaderMarker had its own unique array.
Furthermore, all these arrays had a constant size. Therefore include
this array in the FLACHeaderMarker struct.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/flac_parser.c

index 5d0705ce631f7563ec5a305aa99a6594be2495e3..2658d3c4dc2294ac4dc770fc16777893dee22998 100644 (file)
@@ -58,8 +58,9 @@
 
 typedef struct FLACHeaderMarker {
     int offset;       /**< byte offset from start of FLACParseContext->buffer */
-    int *link_penalty;  /**< pointer to array of local scores between this header
-                           and the one at a distance equal array position     */
+    int link_penalty[FLAC_MAX_SEQUENTIAL_HEADERS]; /**< array of local scores
+                           between this header and the one at a distance equal
+                           array position                                     */
     int max_score;    /**< maximum score found after checking each child that
                            has a valid CRC                                    */
     FLACFrameInfo fi; /**< decoded frame header info                          */
@@ -190,14 +191,6 @@ static int find_headers_search_validate(FLACParseContext *fpc, int offset)
         }
         (*end_handle)->fi           = fi;
         (*end_handle)->offset       = offset;
-        (*end_handle)->link_penalty = av_malloc(sizeof(int) *
-                                            FLAC_MAX_SEQUENTIAL_HEADERS);
-        if (!(*end_handle)->link_penalty) {
-            av_freep(end_handle);
-            av_log(fpc->avctx, AV_LOG_ERROR,
-                   "couldn't allocate link_penalty\n");
-            return AVERROR(ENOMEM);
-        }
 
         for (i = 0; i < FLAC_MAX_SEQUENTIAL_HEADERS; i++)
             (*end_handle)->link_penalty[i] = FLAC_HEADER_NOT_PENALIZED_YET;
@@ -559,7 +552,6 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
                        curr->max_score, curr->offset, curr->next->offset);
             }
             temp = curr->next;
-            av_freep(&curr->link_penalty);
             av_free(curr);
             fpc->nb_headers_buffered--;
         }
@@ -584,12 +576,10 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
 
         for (curr = fpc->headers; curr != fpc->best_header; curr = temp) {
             temp = curr->next;
-            av_freep(&curr->link_penalty);
             av_free(curr);
             fpc->nb_headers_buffered--;
         }
         fpc->headers = fpc->best_header->next;
-        av_freep(&fpc->best_header->link_penalty);
         av_freep(&fpc->best_header);
         fpc->nb_headers_buffered--;
     }
@@ -745,7 +735,6 @@ static void flac_parse_close(AVCodecParserContext *c)
 
     while (curr) {
         temp = curr->next;
-        av_freep(&curr->link_penalty);
         av_free(curr);
         curr = temp;
     }