Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / libavcodec / pthread_slice.c
index edfe9c6..fea989f 100644 (file)
@@ -201,7 +201,7 @@ int ff_slice_thread_init(AVCodecContext *avctx)
     if (!c)
         return -1;
 
-    c->workers = av_mallocz(sizeof(pthread_t)*thread_count);
+    c->workers = av_mallocz_array(thread_count, sizeof(pthread_t));
     if (!c->workers) {
         av_free(c);
         return -1;
@@ -266,15 +266,18 @@ int ff_alloc_entries(AVCodecContext *avctx, int count)
     if (avctx->active_thread_type & FF_THREAD_SLICE)  {
         SliceThreadContext *p = avctx->internal->thread_ctx;
         p->thread_count  = avctx->thread_count;
-        p->entries       = av_mallocz(count * sizeof(int));
+        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(p->thread_count * sizeof(pthread_mutex_t));
-        p->progress_cond  = av_malloc(p->thread_count * sizeof(pthread_cond_t));
 
         for (i = 0; i < p->thread_count; i++) {
             pthread_mutex_init(&p->progress_mutex[i], NULL);