Skip to content
/ server Public

MDEV-36929: Warning: Memory not freed: 32 on SELECT COLUMN_JSON()#4734

Open
abhishek593 wants to merge 1 commit intoMariaDB:10.6from
abhishek593:MDEV-36929
Open

MDEV-36929: Warning: Memory not freed: 32 on SELECT COLUMN_JSON()#4734
abhishek593 wants to merge 1 commit intoMariaDB:10.6from
abhishek593:MDEV-36929

Conversation

@abhishek593
Copy link

Item_func_dyncol_json::val_str() used an internal DYNAMIC_STRING without ensuring it was freed in all execution paths. Fixed by initializing the DYNAMIC_STRING with bzero and calling dynstr_free() on both success and error paths.

@grooverdan grooverdan added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 5, 2026
Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. This is a preliminary review.

This can be fixed in a variety of ways.

One way would be to rely heavily on RAII patterns: have destructors for everything to make sure they are properly called when the PC goes out of scope for these. This will basically fix a class of bugs: past, present and future. At the expense of non-optimal code in certain cases.

Another way would be to hand-craft initialization and de-initialization of data structures at exactly the right time so that memory profiling tools can detect use of uninitialized data and there's no CPU lost in needless double initializing and de-initializing just so that it's "neat". This of course includes awareness of any side effects functions might have on the data structures they operate on.

This review is done in the latter style. As this seems to be the preferred style.

Item_func_dyncol_json::val_str() used an internal DYNAMIC_STRING
without ensuring it was freed when mariadb_dyncol_json failed.

Fixed by freeing the string in the failure case.
@abhishek593
Copy link
Author

@gkodinov I agree with all the points. I didn't look closely on how init_dynamic_string() handled the struct initialization, and that's why I added bzero call to json. I have made the changes suggested by you and also added the test.

Copy link
Member

@gkodinov gkodinov 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 for working on this with me. Stay tuned for the final review please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

5 participants