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

windowing/gbm/drm: fix OpenDrm() related memory leak #22273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

repojohnray
Copy link
Contributor

Description

This commit fixes an issue detected by the sanitizer which generates a minor memory leak. Indeed the functions return a string allocated with strdup(), this commit adds the proper "Deleter". The logs are available below.

Motivation and context

The goal is to clean up some issues detected by the sanitizer.

How has this been tested?

The option "-fsanitize=leak" is required and should be passed to the compiler and the linker. For a fully sanitized executable, you could use the following options: "-fsanitize=bounds -fsanitize=address -fsanitize=undefined -fsanitize=unreachable -fsanitize=bool -fsanitize=enum -fsanitize=leak -fsanitize-recover=address"

An example below, or you could use the cmake option: -DECM_ENABLE_SANITIZERS
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS_DEBUG="-ggdb -O2 -fno-omit-frame-pointer -fsanitize=leak" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=leak" -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=leak"

The python library interferes with the sanitizer, "export PYTHONMALLOC=malloc" is not sufficient to fix this issue. Removing "runner.py" could be sufficient to fix this problem, otherwise disabling CPythonInvoker() is required.

What is the effect on users?

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@repojohnray
Copy link
Contributor Author

Direct leak of 15 byte(s) in 1 object(s) allocated from:
    #0 0x7f8df09050 in __interceptor_strdup (/usr/lib64/libasan.so.6+0x59050)
    #1 0x7f6fd6a6f0 in drmGetDeviceNameFromFd2 (/usr/X11R6/lib64/libdrm.so.2+0xa6f0)
    #2 0x76d8a8c in KODI::WINDOWING::GBM::CDRMUtils::OpenDrm(bool) xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/windowing/gbm/drm/DRMUtils.cpp:374
    #3 0x76ceb20 in KODI::WINDOWING::GBM::CDRMAtomic::InitDrm() xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/windowing/gbm/drm/DRMAtomic.cpp:198
    #4 0x76c6424 in KODI::WINDOWING::GBM::CWinSystemGbm::InitWindowSystem() xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/windowing/gbm/WinSystemGbm.cpp:86
    #5 0x76c95dc in KODI::WINDOWING::GBM::CWinSystemGbmEGLContext::InitWindowSystemEGL(int, int) xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp:21
    #6 0x76ca33c in KODI::WINDOWING::GBM::CWinSystemGbmGLESContext::InitWindowSystem() xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp:63
    #7 0x45173d0 in CApplication::CreateGUI() xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/application/Application.cpp:502
    #8 0x38d89c4 in XBMC_Run xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/platform/xbmc.cpp:36
    #9 0x8a3f1c in main xbmc-9b80ca8a0533ad46948949c12c69dfed837274eb/xbmc/platform/posix/main.cpp:71
    #10 0x7f6f96731c  (/lib64/libc.so.6+0x2731c)
    #11 0x7f6f9673f4 in __libc_start_main (/lib64/libc.so.6+0x273f4)
    #12 0x91d3ec in _start (/usr/local/lib64/kodi/kodi.bin+0x91d3ec)

@@ -368,20 +368,23 @@ bool CDRMUtils::OpenDrm(bool needConnector)

PrintDrmDeviceInfo(device);

const char* renderPath = drmGetRenderDeviceNameFromFd(m_fd);
m_renderDevicePath = std::unique_ptr<const char, StrdupDeleter>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I like custom deleters this seems like an odd one. I think I would rather convert to a std::string.

This could be done with a helper function that wraps the c methods and still free the char*.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lrusak, we could, but these functions return a strdup() string which is usable as is and the strdup() string is allocated using malloc() which requires a free() anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Windowing Platform: Linux Type: Fix non-breaking change which fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants