Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential exception and resource leak #139

Merged
merged 1 commit into from
May 24, 2024

Conversation

xelement
Copy link

@xelement xelement commented May 11, 2024

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

Signed-off-by: Xelement Liu <xelementliu@tencent.com>
@xelement xelement marked this pull request as ready for review May 11, 2024 03:55
@mav-intel mav-intel merged commit e71b1ef into intel:main May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants