diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2019-10-06 07:01:14 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2019-10-07 22:27:18 +0200 |
commit | d03c3e85176436d06b0367b6dd926645d46a2083 (patch) | |
tree | cfeb8c9dfe91e660d200e784862787d13fd10748 | |
parent | 5e546864b09379910721b35a14713982d933d9dd (diff) | |
download | ffmpeg-d03c3e85176436d06b0367b6dd926645d46a2083.tar.gz |
avcodec/flac_parser: Don't allocate array separately
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>
-rw-r--r-- | libavcodec/flac_parser.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c index 5d0705ce63..2658d3c4dc 100644 --- a/libavcodec/flac_parser.c +++ b/libavcodec/flac_parser.c @@ -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; } |