-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
base: master
Are you sure you want to change the base?
Conversation
|
@@ -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>( |
There was a problem hiding this comment.
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*
.
There was a problem hiding this comment.
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.
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
Checklist: