diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c index 334aaac0fc5f2e436123e55761b0e7076f534a63..fea989fc4c985bf0e8a7a0b40bf09c48823553a8 100644 --- a/libavcodec/pthread_slice.c +++ b/libavcodec/pthread_slice.c @@ -268,13 +268,16 @@ int ff_alloc_entries(AVCodecContext *avctx, int count) p->thread_count = avctx->thread_count; p->entries = av_mallocz_array(count, sizeof(int)); - if (!p->entries) { + p->progress_mutex = av_malloc_array(p->thread_count, sizeof(pthread_mutex_t)); + p->progress_cond = av_malloc_array(p->thread_count, sizeof(pthread_cond_t)); + + if (!p->entries || !p->progress_mutex || !p->progress_cond) { + av_freep(&p->entries); + av_freep(&p->progress_mutex); + av_freep(&p->progress_cond); return AVERROR(ENOMEM); } - p->entries_count = count; - p->progress_mutex = av_malloc_array(p->thread_count, sizeof(pthread_mutex_t)); - p->progress_cond = av_malloc_array(p->thread_count, sizeof(pthread_cond_t)); for (i = 0; i < p->thread_count; i++) { pthread_mutex_init(&p->progress_mutex[i], NULL);