Skip to content

Commit

Permalink
[Encode] Fix Coverity issue in av1 (#5823)
Browse files Browse the repository at this point in the history
Avoid resource leak when function returns on error

Co-authored-by: Yao, Leyu <[email protected]>
  • Loading branch information
2 people authored and Sherry-Lin committed Sep 28, 2023
1 parent 054d1be commit 30963ed
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void AV1EncToolsCommon::InitInternal(const FeatureBlocks& /*blocks*/, TPushII Pu
MFX_CHECK(bEncTools, MFX_ERR_NONE);
MFX_CHECK(!m_pEncTools, MFX_ERR_NONE);

mfxEncTools* encTools = GetEncTools(par);
m_pEncTools = GetEncTools(par);
mfxEncToolsCtrlExtDevice extBufDevice = {};
mfxEncToolsCtrlExtAllocator extBufAlloc = {};
mfxExtBuffer* ExtParam[2] = {};
Expand Down Expand Up @@ -389,47 +389,47 @@ void AV1EncToolsCommon::InitInternal(const FeatureBlocks& /*blocks*/, TPushII Pu
MFX_CHECK_STS(sts);

m_bEncToolsInner = false;
if (!(encTools && encTools->Context))
if (!(m_pEncTools && m_pEncTools->Context))
{
encTools = MFXVideoENCODE_CreateEncTools(par);
m_bEncToolsInner = !!encTools;
m_pEncTools = MFXVideoENCODE_CreateEncTools(par);
m_bEncToolsInner = !!m_pEncTools;
}
if (encTools)

m_destroy = [this]()
{
if (m_bEncToolsInner)
MFXVideoENCODE_DestroyEncTools(m_pEncTools);
m_bEncToolsInner = false;

};

if (m_pEncTools)
{
mfxExtEncToolsConfig supportedConfig = {};

encTools->GetSupportedConfig(encTools->Context, &supportedConfig, &m_EncToolCtrl);
m_pEncTools->GetSupportedConfig(m_pEncTools->Context, &supportedConfig, &m_EncToolCtrl);

if (CorrectVideoParams(par, supportedConfig))
MFX_RETURN(MFX_ERR_INCOMPATIBLE_VIDEO_PARAM);

SetDefaultConfig(par, m_EncToolConfig, caps.ForcedSegmentationSupport);

sts = encTools->Init(encTools->Context, &m_EncToolConfig, &m_EncToolCtrl);
sts = m_pEncTools->Init(m_pEncTools->Context, &m_EncToolConfig, &m_EncToolCtrl);
MFX_CHECK_STS(sts);

sts = encTools->GetActiveConfig(encTools->Context, &m_EncToolConfig);
sts = m_pEncTools->GetActiveConfig(m_pEncTools->Context, &m_EncToolConfig);
MFX_CHECK_STS(sts);

encTools->GetDelayInFrames(encTools->Context, &m_EncToolConfig, &m_EncToolCtrl, &m_maxDelay);
m_pEncTools->GetDelayInFrames(m_pEncTools->Context, &m_EncToolConfig, &m_EncToolCtrl, &m_maxDelay);

auto& taskMgrIface = TaskManager::TMInterface::Get(strg);
auto& tm = taskMgrIface.m_Manager;

S_ET_SUBMIT = tm.AddStage(tm.S_NEW);
S_ET_QUERY = tm.AddStage(S_ET_SUBMIT);

m_pEncTools = encTools;
}

m_destroy = [this]()
{
if (m_bEncToolsInner)
MFXVideoENCODE_DestroyEncTools(m_pEncTools);
m_bEncToolsInner = false;

};

return MFX_ERR_NONE;
});

Expand Down

0 comments on commit 30963ed

Please sign in to comment.