8000 Free `userdata` if plugin_register_complex_read() has failed. by rpv-tomsk · Pull Request #2349 · collectd/collectd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 3 commits into from
Jul 24, 2017

Conversation

rpv-tomsk
Copy link
Contributor
@rpv-tomsk rpv-tomsk commented Jul 6, 2017

Citation from Collectd wiki (https://collectd.org/wiki/index.php/User_data_t):

If the callback is deleted or callback registration is failed, the struct is freed using the my_config_free function.

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 calls create_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() calls destroy_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.

@rpv-tomsk rpv-tomsk force-pushed the fix-register-complex-read branch 3 times, most recently from 8eb6404 to 0bdfdca Compare July 9, 2017 15:32
@rpv-tomsk rpv-tomsk force-pushed the fix-register-complex-read branch from 0bdfdca to 53e7e60 Compare July 20, 2017 07:41
@rpv-tomsk
Copy link
Contributor Author

Hi Florian,
please review and merge this.

Thanks!

Rebased, passed through clang-format. cc @octo

Copy link
Member
@octo octo left a 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

8000
@@ -345,6 +349,7 @@ static int create_register_callback(llist_t **list, /* {{{ */

cf = calloc(1, sizeof(*cf));
if (cf == NULL) {
free_userdata(*ud);
Copy link
Member

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.

Copy link
Contributor Author
@rpv-tomsk rpv-tomsk Jul 24, 2017

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.

@octo octo added the Cleanup label Jul 24, 2017
@octo octo added this to the Features milestone Jul 24, 2017
Pavel Rochnyack added 2 commits July 24, 2017 13:31
…stering it.

The message `Check for duplicate "LoadPlugin" lines` is obsolete, as there is a special check in `plugin_load()` for this case.
@rpv-tomsk rpv-tomsk force-pushed the fix-register-complex-read branch 2 times, most recently from e8b649e to ff0d8b0 Compare July 24, 2017 07:07
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.
Copy link
Member
@octo octo left a 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!

@octo octo merged commit d1d1a79 into collectd:master Jul 24, 2017
@rpv-tomsk rpv-tomsk deleted the fix-register-complex-read branch July 24, 2017 08:25
@octo octo modified the milestones: Features, 5.8 Oct 11, 2017
@maryamtahhan maryamtahhan mentioned this pull request Oct 12, 2017
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0