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

MDEV-31636 Memory leak in Sys_var_gtid_binlog_state::do_check() #3523

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

Conversation

DaveGosselin-MariaDB
Copy link
Member

@DaveGosselin-MariaDB DaveGosselin-MariaDB commented Sep 17, 2024

Move memory allocations performed during Sys_var_gtid_binlog_state::do_check to Sys_var_gtid_binlog_state::global_update where they will be freed before the latter method returns.

@DaveGosselin-MariaDB DaveGosselin-MariaDB self-assigned this Sep 17, 2024
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

sql/sys_vars.cc Outdated
{
if (!var->save_result_exists)
return;
auto data= (gtid_binlog_state_data *)var->save_result.ptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

ptr is allocated in do_check() somewhat quite surprisingly 'cos it all looks to me this could be done inside
`var->update().

I'd consider that first. If turns true indeed, we naturally shall carefully check all existing class' do_check() (to my browsing there's none but ours replication's).

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, though it logically makes sense for the actual validation of the input value to be in do_check(). Sys_var_gtid_slave_pos has a slightly different, yet still consistent to check semantics pattern, which in Sys_var_gtid_slave_pos::do_check() validates the value and saves the string on thd, and then uses that string in Sys_var_gtid_slave_pos::global_update() in a load. Can we follow that pattern here? (Though @DaveGosselin-MariaDB I recall in our discussion you mentioned trying to save something on the thread, and it not working. Is this what you tried?).

Generally speaking though, I' say whichever pattern we pick, Sys_var_gtid_binlog_state and Sys_var_gtid_slave_pos should probably follow the same pattern in the source code for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey Brandon, I wasn't saving something on the thread but rather marking variables such that an on_error phase could be executed over all affected variables so that they may handle any cleanup in their own implementation-dependent way (see 90eab64 )

Copy link
Contributor

@andrelkin andrelkin left a comment

Choose a reason for hiding this comment

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

Thanks Dave for a good piece. It all seems to provide a solution. However let's look at the issue at a different angle I am suggesting in a note.

@DaveGosselin-MariaDB
Copy link
Member Author

Thanks Dave for a good piece. It all seems to provide a solution. However let's look at the issue at a different angle I am suggesting in a note.

Thank you Andrei 😄 I will investigate the other angle.

Move memory allocations performed during Sys_var_gtid_binlog_state::do_check
to Sys_var_gtid_binlog_state::global_update where they will be freed before
the latter method returns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants