Skip to content

Commit

Permalink
Fix Coverity issues
Browse files Browse the repository at this point in the history
CID/Type:
187157 Explicit null dereferenced
656172 Dereference after null check
602228 Dereference before null check

Tracked-On: OAM-126078
Signed-off-by: Wan, Hao <[email protected]>
  • Loading branch information
harvan committed Oct 8, 2024
1 parent 656fff2 commit 8e1ad6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
46 changes: 26 additions & 20 deletions c2_components/src/mfx_c2_decoder_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2177,19 +2177,20 @@ void MfxC2DecoderComponent::DoWork(std::unique_ptr<C2Work>&& work)
if (it != m_pendingWorks.end()) {
work = std::move(it->second);
m_pendingWorks.erase(it);

if (work) {
if (flushing) {
m_flushedWorks.push_back(std::move(work));
} else {
FillEmptyWork(std::move(work), res);
}
}
} else {
MFX_DEBUG_TRACE_STREAM("Not found C2Work, index = " << incoming_frame_index.peeku());
// If not found, it might be removed by WaitWork. We don't need to return an error.
// FatalError(C2_CORRUPTED);
}
}
if (work) {
if (flushing) {
m_flushedWorks.push_back(std::move(work));
} else {
FillEmptyWork(std::move(work), res);
}
}
}
}

Expand Down Expand Up @@ -2334,19 +2335,20 @@ void MfxC2DecoderComponent::WaitWork(MfxC2FrameOut&& frame_out, mfxSyncPoint syn

MfxC2FrameOut frameOutVpp;
std::shared_ptr<mfxFrameSurface1> mfx_surface_vpp;
if(m_vppConversion) {
AllocateFrame(&frameOutVpp, true);
mfx_surface_vpp = frameOutVpp.GetMfxFrameSurface();

if (mfx_surface_vpp) {
mfxSyncPoint syncp;
mfx_res = m_vpp->RunFrameVPPAsync(mfx_surface.get(), mfx_surface_vpp.get(), NULL, &syncp);
if (MFX_ERR_NONE == mfx_res)
#ifdef USE_ONEVPL
mfx_res = MFXVideoCORE_SyncOperation(m_mfxSession, syncp, MFX_TIMEOUT_INFINITE);
#else
mfx_res = m_pSession->SyncOperation(syncp, MFX_TIMEOUT_INFINITE);
#endif
if (m_vppConversion) {
res = AllocateFrame(&frameOutVpp, true);
if (res == C2_OK) {
mfx_surface_vpp = frameOutVpp.GetMfxFrameSurface();
if (mfx_surface_vpp.get()) {
mfxSyncPoint syncp;
mfx_res = m_vpp->RunFrameVPPAsync(mfx_surface.get(), mfx_surface_vpp.get(), NULL, &syncp);
if (MFX_ERR_NONE == mfx_res)
#ifdef USE_ONEVPL
mfx_res = MFXVideoCORE_SyncOperation(m_mfxSession, syncp, MFX_TIMEOUT_INFINITE);
#else
mfx_res = m_pSession->SyncOperation(syncp, MFX_TIMEOUT_INFINITE);
#endif
}
}
}

Expand Down Expand Up @@ -2387,6 +2389,10 @@ void MfxC2DecoderComponent::WaitWork(MfxC2FrameOut&& frame_out, mfxSyncPoint syn
rect = C2Rect(mfx_surface->Info.CropW, mfx_surface->Info.CropH)
.at(mfx_surface->Info.CropX, mfx_surface->Info.CropY);
} else {
if (mfx_surface_vpp.get() == nullptr) {
res = C2_CORRUPTED;
break;
}
rect = C2Rect(mfx_surface_vpp->Info.CropW, mfx_surface_vpp->Info.CropH)
.at(mfx_surface_vpp->Info.CropX, mfx_surface_vpp->Info.CropY);
}
Expand Down
7 changes: 5 additions & 2 deletions c2_utils/src/mfx_gralloc1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,16 @@ buffer_handle_t MfxGralloc1Module::ImportBuffer(const buffer_handle_t rawHandle)
MFX_DEBUG_TRACE_FUNC;
c2_status_t res = C2_OK;
buffer_handle_t *outBuffer = nullptr;
int32_t gr1_res = (*m_grImportBufferFunc)(m_gralloc1_dev, rawHandle, outBuffer);
buffer_handle_t out = nullptr;

int32_t gr1_res = (*m_grImportBufferFunc)(m_gralloc1_dev, rawHandle, outBuffer);
if (GRALLOC1_ERROR_NONE != gr1_res || nullptr == outBuffer) {
MFX_DEBUG_TRACE_I32(gr1_res);
res = C2_BAD_STATE;
}
buffer_handle_t out = const_cast<buffer_handle_t>(*outBuffer);

if (outBuffer)
out = const_cast<buffer_handle_t>(*outBuffer);

MFX_DEBUG_TRACE__android_c2_status_t(res);
return out;
Expand Down

0 comments on commit 8e1ad6f

Please sign in to comment.