[FFmpeg-devel] [PATCH 04/10] avcodec/flac_parser: Don't allocate array separately
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Sun Oct 6 08:01:14 EEST 2019
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 at gmail.com>
---
sizeof(FLACHeaderMarker) didn't increase for me (on x64) with this
patch, because there are now 2x4 bytes of padding less.
libavcodec/flac_parser.c | 17 +++--------------
1 file 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;
}
--
2.20.1
More information about the ffmpeg-devel
mailing list