Skip to content

Commit f045b37

Browse files
GvencegfxVPLsdm
authored andcommitted
Fix Coverity issues: resource leak and uncaught exceptions in destructors
CID 2984086 (RESOURCE_LEAK): In CreateCmDevice (Linux), device->m_dll was loaded via so_load but not freed via so_free() before delete device in error paths. Added so_free(device->m_dll) before each delete device. CIDs 3558368, 3558369, 3558372, 3558379, 3558386, 3558389, 3558398 (UNCAUGHT_EXCEPT): MFX_STS_TRACE macro creates std::string objects that can throw std::bad_alloc. Since destructors are implicitly noexcept, any exception would call std::terminate(). Wrapped destructor bodies with try-catch(...) to prevent exception propagation. Affected destructors: - mfxSurfaceVulkanImg2DImpl::~mfxSurfaceVulkanImg2DImpl - SurfaceScopedLock::~SurfaceScopedLock - vaapi_buffer_wrapper::~vaapi_buffer_wrapper - vaapi_surface_wrapper::~vaapi_surface_wrapper - mfxSurfaceVAAPIImpl::~mfxSurfaceVAAPIImpl - VACopyWrapper::SurfaceWrapper::~SurfaceWrapper - LinuxVideoAccelerator::~LinuxVideoAccelerator
1 parent 0613d11 commit f045b37

5 files changed

Lines changed: 42 additions & 16 deletions

File tree

_studio/mfx_lib/ext/cmrt_cross_platform/src/cmrt_cross_platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,15 @@ INT CreateCmDevice(CmDevice *& pD, UINT & version, VADisplay va_dpy, UINT mode)
521521
CreateCmDeviceLinuxFuncTypeEx createFunc = (CreateCmDeviceLinuxFuncTypeEx)so_get_addr(device->m_dll, FUNC_NAME_CREATE_CM_DEVICE_EX);
522522
if (createFunc == 0)
523523
{
524+
so_free(device->m_dll);
524525
delete device;
525526
return CM_FAILURE;
526527
}
527528

528529
INT res = createFunc(device->m_linux, version, va_dpy, mode);
529530
if (res != CM_SUCCESS)
530531
{
532+
so_free(device->m_dll);
531533
delete device;
532534
return CM_FAILURE;
533535
}

_studio/shared/include/libmfx_allocator_vaapi.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ class SurfaceScopedLock
7878

7979
~SurfaceScopedLock()
8080
{
81-
if (m_mapped) std::ignore = MFX_STS_TRACE(Unmap());
82-
if (m_image_created) std::ignore = MFX_STS_TRACE(DestroyImage());
81+
try
82+
{
83+
if (m_mapped) std::ignore = MFX_STS_TRACE(Unmap());
84+
if (m_image_created) std::ignore = MFX_STS_TRACE(DestroyImage());
85+
}
86+
catch (...) {}
8387
}
8488

8589
mfxStatus DeriveImage()

_studio/shared/src/libmfx_allocator_vaapi.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,11 @@ vaapi_buffer_wrapper::vaapi_buffer_wrapper(const mfxFrameInfo &info, VADisplayWr
851851

852852
vaapi_buffer_wrapper::~vaapi_buffer_wrapper()
853853
{
854-
std::ignore = MFX_STS_TRACE(vaDestroyBuffer(*m_pVADisplay, m_resource_id));
854+
try
855+
{
856+
std::ignore = MFX_STS_TRACE(vaDestroyBuffer(*m_pVADisplay, m_resource_id));
857+
}
858+
catch (...) {}
855859
}
856860

857861
mfxStatus vaapi_buffer_wrapper::Lock(mfxFrameData& frame_data, mfxU32 flags)
@@ -1066,10 +1070,14 @@ mfxStatus vaapi_surface_wrapper::CopyImportSurfaceVAAPI(const mfxFrameInfo& info
10661070

10671071
vaapi_surface_wrapper::~vaapi_surface_wrapper()
10681072
{
1069-
if (!m_imported)
1073+
try
10701074
{
1071-
std::ignore = MFX_STS_TRACE(vaDestroySurfaces(*m_pVADisplay, &m_resource_id, 1));
1075+
if (!m_imported)
1076+
{
1077+
std::ignore = MFX_STS_TRACE(vaDestroySurfaces(*m_pVADisplay, &m_resource_id, 1));
1078+
}
10721079
}
1080+
catch (...) {}
10731081
}
10741082

10751083
mfxStatus vaapi_surface_wrapper::Lock(mfxFrameData& frame_data, mfxU32 flags)
@@ -1304,16 +1312,20 @@ mfxSurfaceVAAPIImpl::mfxSurfaceVAAPIImpl(const mfxSurfaceHeader& export_header,
13041312

13051313
mfxSurfaceVAAPIImpl::~mfxSurfaceVAAPIImpl()
13061314
{
1307-
if (mfxSurfaceInterface::Header.SurfaceFlags & MFX_SURFACE_FLAG_EXPORT_COPY)
1308-
{
1309-
std::ignore = MFX_STS_TRACE(vaDestroySurfaces(*m_pVADisplay, &m_surface_id, 1));
1310-
}
1311-
// In reality excessive check, with correct refmanagement original surface should be alive
1312-
else if (GetParentSurface())
1315+
try
13131316
{
1314-
// Release original surface, VASurfaceID can be destroyed now
1315-
GetParentSurface()->Release();
1317+
if (mfxSurfaceInterface::Header.SurfaceFlags & MFX_SURFACE_FLAG_EXPORT_COPY)
1318+
{
1319+
std::ignore = MFX_STS_TRACE(vaDestroySurfaces(*m_pVADisplay, &m_surface_id, 1));
1320+
}
1321+
// In reality excessive check, with correct refmanagement original surface should be alive
1322+
else if (GetParentSurface())
1323+
{
1324+
// Release original surface, VASurfaceID can be destroyed now
1325+
GetParentSurface()->Release();
1326+
}
13161327
}
1328+
catch (...) {}
13171329
}
13181330

13191331
/* EOF */

_studio/shared/src/libmfx_core_vaapi.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ class VACopyWrapper
173173

174174
~SurfaceWrapper()
175175
{
176-
if (m_id != VA_INVALID_SURFACE && m_bDestroySurface)
177-
std::ignore = MFX_STS_TRACE(vaDestroySurfaces(m_dpy, &m_id, 1));
176+
try
177+
{
178+
if (m_id != VA_INVALID_SURFACE && m_bDestroySurface)
179+
std::ignore = MFX_STS_TRACE(vaDestroySurfaces(m_dpy, &m_id, 1));
180+
}
181+
catch (...) {}
178182
}
179183

180184
VASurfaceID GetId() const

_studio/shared/umc/io/umc_va/src/umc_va_linux.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ LinuxVideoAccelerator::LinuxVideoAccelerator(void)
348348

349349
LinuxVideoAccelerator::~LinuxVideoAccelerator(void)
350350
{
351-
Close();
351+
try
352+
{
353+
Close();
354+
}
355+
catch (...) {}
352356
}
353357

354358
Status LinuxVideoAccelerator::Init(VideoAcceleratorParams* pInfo)

0 commit comments

Comments
 (0)