ref: 41b4ecb06b544e8315f5f48ccf88706e2b8f71c7
parent: a26955e4445917a7a38d4a29c752e2d6c76055a4
parent: 4b97dcb367ea654a29b8167e5a883879d05326eb
author: sijchen <sijchen@cisco.com>
date: Wed Feb 17 04:52:30 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
@@ -1001,7 +1001,23 @@
pDq = NULL;
}
+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) {
@@ -1243,7 +1259,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);
@@ -2206,19 +2222,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;
}