History

avoid memory problem when mem alloc failed during initializing pRefList

sijchen committed 10 years ago

Commit 4b97dcb1 parent 8b120601 file · +20 −14Browse files

Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 1 file). Show all

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+20−14
@@ -952,6 +952,23 @@ void FreeMbCache (SMbCache* pMbCache, CMemoryAlign* pMa) { · 951 unmodified lines
952952 }
953953 }
954954
955+void FreeRefList (SRefList*& pRefList, CMemoryAlign* pMa, const int iMaxNumRefFrame) {
956+ if (NULL == pRefList) {
957+ return;
958+ }
959+
960+ int32_t iRef = 0;
961+ do {
962+ if (pRefList->pRef[iRef] != NULL) {
963+ FreePicture (pMa, &pRefList->pRef[iRef]);
964+ }
965+ ++ iRef;
966+ } while (iRef < 1 + iMaxNumRefFrame);
967+
968+ pMa->WelsFree (pRefList, "pRefList");
969+ pRefList = NULL;
970+}
971+
955972 static int32_t WelsGenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex,
956973 const int32_t iDlayerCount, const int32_t kiSpsId,
957974 SWelsSPS*& pSps, SSubsetSps*& pSubsetSps, bool bSVCBaselayer) {
@@ -1193,7 +1210,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 235 unmodified lines
11931210 do {
11941211 pRefList->pRef[i] = AllocPicture (pMa, kiWidth, kiHeight, true,
11951212 (iDlayerIndex == iDlayerCount - 1) ? kiNeedFeatureStorage : 0); // to use actual size of current layer
1196− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeMemorySvc (ppCtx))
1213+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeRefList (pRefList, pMa, iNumRef))
11971214 ++ i;
11981215 } while (i < 1 + iNumRef);
11991216
@@ -2203,19 +2220,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 1003 unmodified lines
22032220 if (NULL != pCtx->ppRefPicListExt && pParam != NULL) {
22042221 ilayer = 0;
22052222 while (ilayer < pParam->iSpatialLayerNum) {
2206− SRefList* pRefList = pCtx->ppRefPicListExt[ilayer];
2207− if (NULL != pRefList) {
2208− int32_t iRef = 0;
2209− do {
2210− if (pRefList->pRef[iRef] != NULL) {
2211− FreePicture (pMa, &pRefList->pRef[iRef]);
2212− }
2213− ++ iRef;
2214− } while (iRef < 1 + pParam->iMaxNumRefFrame);
2215−
2216− pMa->WelsFree (pCtx->ppRefPicListExt[ilayer], "ppRefPicListExt[]");
2217− pCtx->ppRefPicListExt[ilayer] = NULL;
2218− }
2223+ FreeRefList (pCtx->ppRefPicListExt[ilayer], pMa, pParam->iMaxNumRefFrame);
2224+ pCtx->ppRefPicListExt[ilayer] = NULL;
22192225 ++ ilayer;
22202226 }
22212227

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t