@@ -3406,7 +3406,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
av_freep(&s->sh.offset);
av_freep(&s->sh.size);
- for (i = 1; i < s->threads_number; i++) {
+ for (i = 1; i < FFMIN(s->threads_number, MAX_NB_THREADS); i++) {
HEVCLocalContext *lc = s->HEVClcList[i];
if (lc) {
av_freep(&s->HEVClcList[i]);
@@ -3608,6 +3608,10 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx)
s->threads_type = FF_THREAD_FRAME;
else
s->threads_type = FF_THREAD_SLICE;
+ if (s->threads_type == FF_THREAD_SLICE && s->threads_number > MAX_NB_THREADS) {
+ av_log(s->avctx, AV_LOG_WARNING, "too many threads (%d), reducing to %d.\n", s->threads_number, MAX_NB_THREADS);
+ s->threads_number = MAX_NB_THREADS;
+ }
return 0;
}