ref: 4b97dcb367ea654a29b8167e5a883879d05326eb
parent: 8b1206001c27db9828a659f07963154d74cbc41c
author: sijchen <sijchen@cisco.com>
date: Tue Feb 16 05:05:49 EST 2016
avoid memory problem when mem alloc failed during initializing pRefList
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -952,6 +952,23 @@
}
}
+void FreeRefList (SRefList*& pRefList, CMemoryAlign* pMa, const int iMaxNumRefFrame) {
+ if (NULL == pRefList) {
+ return;
+ }
+
+ int32_t iRef = 0;
+ do {
+ if (pRefList->pRef[iRef] != NULL) {
+ FreePicture (pMa, &pRefList->pRef[iRef]);
+ }
+ ++ iRef;
+ } while (iRef < 1 + iMaxNumRefFrame);
+
+ pMa->WelsFree (pRefList, "pRefList");
+ pRefList = NULL;
+}
+
static int32_t WelsGenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex,
const int32_t iDlayerCount, const int32_t kiSpsId,
SWelsSPS*& pSps, SSubsetSps*& pSubsetSps, bool bSVCBaselayer) {
@@ -1193,7 +1210,7 @@
do {
pRefList->pRef[i] = AllocPicture (pMa, kiWidth, kiHeight, true,
(iDlayerIndex == iDlayerCount - 1) ? kiNeedFeatureStorage : 0); // to use actual size of current layer
- WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeMemorySvc (ppCtx))
+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeRefList (pRefList, pMa, iNumRef))
++ i;
} while (i < 1 + iNumRef);
@@ -2203,19 +2220,8 @@
if (NULL != pCtx->ppRefPicListExt && pParam != NULL) {
ilayer = 0;
while (ilayer < pParam->iSpatialLayerNum) {
- SRefList* pRefList = pCtx->ppRefPicListExt[ilayer];
- if (NULL != pRefList) {
- int32_t iRef = 0;
- do {
- if (pRefList->pRef[iRef] != NULL) {
- FreePicture (pMa, &pRefList->pRef[iRef]);
- }
- ++ iRef;
- } while (iRef < 1 + pParam->iMaxNumRefFrame);
-
- pMa->WelsFree (pCtx->ppRefPicListExt[ilayer], "ppRefPicListExt[]");
- pCtx->ppRefPicListExt[ilayer] = NULL;
- }
+ FreeRefList (pCtx->ppRefPicListExt[ilayer], pMa, pParam->iMaxNumRefFrame);
+ pCtx->ppRefPicListExt[ilayer] = NULL;
++ ilayer;
}