[FFmpeg-devel] [PATCH 1/4] avcodec/hevcdec: Combine multiple allocations
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Wed Jan 5 23:18:11 EET 2022
Reduces the number of allocs and frees.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
libavcodec/hevcdec.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 8d7a4f7147..568bdb5ab7 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2621,17 +2621,15 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
const uint8_t *data = nal->data;
int length = nal->size;
HEVCLocalContext *lc = s->HEVClc;
- int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
- int *arg = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));
+ int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, 2 * sizeof(int));
+ int *arg;
int64_t offset;
int64_t startheader, cmpt = 0;
int i, j, res = 0;
- if (!ret || !arg) {
- av_free(ret);
- av_free(arg);
+ if (!ret)
return AVERROR(ENOMEM);
- }
+ arg = ret + s->sh.num_entry_point_offsets + 1;
if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * s->ps.sps->ctb_width >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) {
av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
@@ -2716,7 +2714,6 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
res += ret[i];
error:
av_free(ret);
- av_free(arg);
return res;
}
--
2.32.0
More information about the ffmpeg-devel
mailing list