Fix potential exception and resource leak #139
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
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.
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
How Tested
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
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
libvpl/src/mfx_dispatcher_vpl_loader.cpp:line 1135
Same as 2
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