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
tracing: Fix handle leak in TracepointProvider #12652
Conversation
@@ -39,6 +39,7 @@ void TracepointProvider::verify_config(const struct md_config_t *conf) { | |||
void *handle = dlopen(m_library.c_str(), RTLD_NOW); | |||
if (handle != NULL) { | |||
m_enabled = true; | |||
free(handle); |
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.
dlclose(handle)?
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.
@xiexingguo that would unload the shared object and I'm not sure that's the intention here? You're right though that free is probably not the way to go in hindsight. @dillaman could we get your opinion here?
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.
Perhaps making the handle a member and calling dlclose in the destructor?
fee20e2
to
6872601
Compare
I've changed this to be more of an RAII approach which I think is better. @dillaman still like your opinion when you are around. |
void *handle = dlopen(m_library.c_str(), RTLD_NOW); | ||
if (handle != NULL) { | ||
m_handle = dlopen(m_library.c_str(), RTLD_NOW); | ||
if (m_handle != NULL) { |
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.
Nit: I would now eliminate the m_enabled
member variable and just use m_handle != nullptr
to determine if it's enabled.
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.
Yes, more like @dragonylffly solution in #12673 Agreed, it's a good idea.
Silences Coverity 1397733 Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
6872601
to
756c201
Compare
Updated. Many thanks to @dragonylffly for his contribution. |
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.
lgtm
Silences Coverity 1397733
Signed-off-by: Brad Hubbard bhubbard@redhat.com