shithub: openh264

Download patch

ref: cc675f9fd14f9fbde55ee0408adb9e4b0edc9ed3
parent: a26955e4445917a7a38d4a29c752e2d6c76055a4
author: sijchen <sijchen@cisco.com>
date: Tue Feb 16 06:58:24 EST 2016

add error handling in memory allocation failed case

--- a/codec/common/src/WelsThreadPool.cpp
+++ b/codec/common/src/WelsThreadPool.cpp
@@ -50,7 +50,19 @@
   m_cBusyThreads = new CWelsList<CWelsTaskThread>();
   m_iMaxThreadNum = 0;
 
-  Init (iMaxThreadNum);
+  if (NULL == m_cWaitedTasks || NULL == m_cIdleThreads || NULL == m_cBusyThreads) {
+    delete m_cWaitedTasks;
+    delete m_cIdleThreads;
+    delete m_cBusyThreads;
+    return;
+  }
+
+  if (WELS_THREAD_ERROR_OK != Init (iMaxThreadNum)) {
+    Uninit();
+    delete m_cWaitedTasks;
+    delete m_cIdleThreads;
+    delete m_cBusyThreads;
+  }
 }
 
 
@@ -175,7 +187,9 @@
     return WELS_THREAD_ERROR_GENERAL;
   }
 
-  pThread->Start();
+  if (WELS_THREAD_ERROR_OK != pThread->Start()) {
+    return WELS_THREAD_ERROR_GENERAL;
+  }
   AddThreadToIdleQueue (pThread);
 
   return WELS_THREAD_ERROR_OK;
--- a/codec/encoder/core/src/wels_task_management.cpp
+++ b/codec/encoder/core/src/wels_task_management.cpp
@@ -63,9 +63,11 @@
 
   IWelsTaskManage* pTaskManage;
   pTaskManage = WELS_NEW_OP (CWelsTaskManageBase(), CWelsTaskManageBase);
+  WELS_VERIFY_RETURN_IF (NULL, NULL == pTaskManage)
 
-  if (pTaskManage) {
-    pTaskManage->Init (pCtx);
+  if ( ENC_RETURN_SUCCESS != pTaskManage->Init (pCtx) ) {
+    delete pTaskManage;
+    pTaskManage = NULL;
   }
   return pTaskManage;
 }
@@ -98,7 +100,7 @@
                                WelsCommon::CWelsThreadPool);
   WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == m_pThreadPool)
 
-  int32_t iReturn = 0;
+  int32_t iReturn = ENC_RETURN_SUCCESS;
   for (int32_t iDid = 0; iDid < MAX_DEPENDENCY_LAYER; iDid++) {
     m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_ENCODING][iDid] = m_cEncodingTaskList[iDid];
     m_pcAllTaskList[CWelsBaseTask::WELS_ENC_TASK_UPDATEMBMAP][iDid] = m_cPreEncodingTaskList[iDid];