History

Avoid memory problem when mem alloc failed during initializing pRefList

sijchen committed 10 years ago

Commit 41b4ecb2 parents a26955e 4b97dcb1 file · +19 −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+19−14
@@ -1001,6 +1001,22 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 1000 unmodified lines
10011001 pDq = NULL;
10021002 }
10031003
1004+void FreeRefList (SRefList*& pRefList, CMemoryAlign* pMa, const int iMaxNumRefFrame) {
1005+ if (NULL == pRefList) {
1006+ return;
1007+ }
1008+
1009+ int32_t iRef = 0;
1010+ do {
1011+ if (pRefList->pRef[iRef] != NULL) {
1012+ FreePicture (pMa, &pRefList->pRef[iRef]);
1013+ }
1014+ ++ iRef;
1015+ } while (iRef < 1 + iMaxNumRefFrame);
1016+
1017+ pMa->WelsFree (pRefList, "pRefList");
1018+ pRefList = NULL;
1019+}
10041020
10051021 static int32_t WelsGenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex,
10061022 const int32_t iDlayerCount, const int32_t kiSpsId,
@@ -1243,7 +1259,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 236 unmodified lines
12431259 do {
12441260 pRefList->pRef[i] = AllocPicture (pMa, kiWidth, kiHeight, true,
12451261 (iDlayerIndex == iDlayerCount - 1) ? kiNeedFeatureStorage : 0); // to use actual size of current layer
1246− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeMemorySvc (ppCtx))
1262+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeRefList (pRefList, pMa, iNumRef))
12471263 ++ i;
12481264 } while (i < 1 + iNumRef);
12491265
@@ -2206,19 +2222,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 956 unmodified lines
22062222 if (NULL != pCtx->ppRefPicListExt && pParam != NULL) {
22072223 ilayer = 0;
22082224 while (ilayer < pParam->iSpatialLayerNum) {
2209− SRefList* pRefList = pCtx->ppRefPicListExt[ilayer];
2210− if (NULL != pRefList) {
2211− int32_t iRef = 0;
2212− do {
2213− if (pRefList->pRef[iRef] != NULL) {
2214− FreePicture (pMa, &pRefList->pRef[iRef]);
2215− }
2216− ++ iRef;
2217− } while (iRef < 1 + pParam->iMaxNumRefFrame);
2218−
2219− pMa->WelsFree (pCtx->ppRefPicListExt[ilayer], "ppRefPicListExt[]");
2220− pCtx->ppRefPicListExt[ilayer] = NULL;
2221− }
2225+ FreeRefList (pCtx->ppRefPicListExt[ilayer], pMa, pParam->iMaxNumRefFrame);
2226+ pCtx->ppRefPicListExt[ilayer] = NULL;
22222227 ++ ilayer;
22232228 }
22242229

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