intel / libvpl

Intel® Video Processing Library (Intel® VPL) API, dispatcher, and examples
https://intel.github.io/libvpl/
MIT License
262 stars 80 forks source link

Fix potential exception and resource leak #139

Closed xelement closed 1 month ago

xelement commented 1 month ago

Issue

  1. If we want to determine memory allocation result,we should use 'new(std::nothrow)' instead of new,because 'new' failed will throw 'std::bad_alloc' exception. It may cause potential exception since modified code path does not have any try catch.

  2. The original code can cause resource leak if just return 'MFX_ERR_MEMORY_ALLOC', see libvpl/src/mfx_dispatcher_vpl_loader.cpp:line 211,276

Solution

  1. Use 'new(std::nothrow)' instead of 'new'
  2. Free resouce before return 'MFX_ERR_MEMORY_ALLOC'

How Tested

  1. libvpl/src/mfx_dispatcher_vpl_loader.cpp:line 211,276 1.1 set *'LibInfo libInfo = nullptr' (If no memory,new (std::nothrow) will return nullptr) 1.2 run vpl-timing with argument '-e' ( run 'MFXEnumImplementations '** function) 1.3 MFXEnumImplementations return 'MFX_ERR_NOT_FOUND',No memory leak,No crash,it was what we desired

  2. libvpl/src/mfx_dispatcher_vpl_loader.cpp:line 999 2.1 set *'ImplInfo implInfo = nullptr' 2.2 run vpl-timing** 2.3 MFXCreateSession return 'MFX_ERR_NOT_FOUND',No memory leak,No crash,it was what we desired

  3. libvpl/src/mfx_dispatcher_vpl_loader.cpp:line 1135 Same as 2

  4. libvpl/src/mfx_dispatcher_vpl_lowlatency.cpp:line 80 4.1 set 'libInfo = nullptr'
    4.2 run vpl-timing with argument '-f' 4.3 MFXCreateSession return 'MFX_ERR_NOT_FOUND',No memory leak,No crash,it was what we desired