ref: f791ac28ec12794a3605541c2760ea814e08c621
parent: de1a70d16444c21b0e5b2b4fcce4f42a6fa09b79
parent: 41b4ecb06b544e8315f5f48ccf88706e2b8f71c7
author: ruil2 <ruil2@cisco.com>
date: Thu Feb 18 05:25:07 EST 2016
Merge pull request #2365 from sijchen/fix_free42 [Encoder] 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;
}