-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Free userdata
if plugin_register_complex_read() has failed.
#2349
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
Conversation
8eb6404
to
0bdfdca
Compare
0bdfdca
to
53e7e60
Compare
Hi Florian, Thanks! Rebased, passed through clang-format. cc @octo |
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.
Hi @rpv-tomsk,
thanks for this! This looks good overall, just one small issue that we should fix before merging.
Best regards,
—octo
src/daemon/plugin.c
Outdated
@@ -345,6 +349,7 @@ static int create_register_callback(llist_t **list, /* {{{ */ | |||
|
|||
8000 | cf = calloc(1, sizeof(*cf)); | ||
if (cf == NULL) { | |||
free_userdata(*ud); |
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.
This dereferences ud
without checking for NULL
. I'd suggest to change free_userdata
to take a user_data_t*
(i.e. a pointer) instead and check for NULL
there.
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.
Updated, thanks!
Things become more clear after this change.
…stering it. The message `Check for duplicate "LoadPlugin" lines` is obsolete, as there is a special check in `plugin_load()` for this case.
e8b649e
to
ff0d8b0
Compare
If `plugin_register_complex_read()` has failed, then `cldap_free` is called which set pointer to NULL. That pointer is accessed by `cldap_shutdown()` callback later.
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, thanks @rpv-tomsk!
Citation from Collectd wiki (https://collectd.org/wiki/index.php/User_data_t):
There are several functions which register callbacks and has
user_data_t
argument:plugin_register_write(), plugin_register_log(), plugin_register_notification(), plugin_register_flush()
- which callscreate_register_callback()
.plugin_register_complex_read()
, which implemented in other way.Most of plugins expects what free() will happen if registration failed.
For first functions group, in case of failure,
create_register_callback()
callsdestroy_callback()
which frees userdata.But there was no code in
plugin_register_complex_read()
for userdata free.That code was added, and some plugins (and Collectd itself) code was adjusted to new behaviour.