avcodec/hevcdec: Move allocation after error checks

While just at it, also use av_calloc() instead of zeroing
the array ourselves in a loop.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/388/head
Andreas Rheinhardt 3 years ago
parent 571e4055dc
commit 5bf4ac9113
  1. 27
      libavcodec/hevcdec.c

@ -2632,31 +2632,25 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
const uint8_t *data = nal->data; const uint8_t *data = nal->data;
int length = nal->size; int length = nal->size;
HEVCLocalContext *lc = s->HEVClc; HEVCLocalContext *lc = s->HEVClc;
int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int)); int *ret;
int64_t offset; int64_t offset;
int64_t startheader, cmpt = 0; int64_t startheader, cmpt = 0;
int i, j, res = 0; int i, j, res = 0;
if (!ret)
return AVERROR(ENOMEM);
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) { 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", av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets, s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
s->ps.sps->ctb_width, s->ps.sps->ctb_height s->ps.sps->ctb_width, s->ps.sps->ctb_height
); );
res = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto error;
} }
for (i = 1; i < s->threads_number; i++) { for (i = 1; i < s->threads_number; i++) {
if (s->HEVClcList[i]) if (s->HEVClcList[i])
continue; continue;
s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext));
if (!s->HEVClcList[i]) { if (!s->HEVClcList[i])
res = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto error;
}
s->HEVClcList[i]->logctx = s->avctx; s->HEVClcList[i]->logctx = s->avctx;
s->HEVClcList[i]->parent = s; s->HEVClcList[i]->parent = s;
} }
@ -2687,8 +2681,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt; offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
if (length < offset) { if (length < offset) {
av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n"); av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
res = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto error;
} }
s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset; s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset;
s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset; s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset;
@ -2704,18 +2697,18 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
atomic_store(&s->wpp_err, 0); atomic_store(&s->wpp_err, 0);
res = ff_slice_thread_allocz_entries(s->avctx, s->sh.num_entry_point_offsets + 1); res = ff_slice_thread_allocz_entries(s->avctx, s->sh.num_entry_point_offsets + 1);
if (res < 0) if (res < 0)
goto error; return res;
for (i = 0; i <= s->sh.num_entry_point_offsets; i++) { ret = av_calloc(s->sh.num_entry_point_offsets + 1, sizeof(*ret));
ret[i] = 0; if (!ret)
} return AVERROR(ENOMEM);
if (s->ps.pps->entropy_coding_sync_enabled_flag) if (s->ps.pps->entropy_coding_sync_enabled_flag)
s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->HEVClcList, ret, s->sh.num_entry_point_offsets + 1); s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->HEVClcList, ret, s->sh.num_entry_point_offsets + 1);
for (i = 0; i <= s->sh.num_entry_point_offsets; i++) for (i = 0; i <= s->sh.num_entry_point_offsets; i++)
res += ret[i]; res += ret[i];
error:
av_free(ret); av_free(ret);
return res; return res;
} }

Loading…
Cancel
Save