Bug #105028 memory leak caused by recv_sys->saved_recs during recovery
Submitted: 24 Sep 2021 4:45 Modified: 24 Sep 2021 5:23
Reporter: alex xing (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0.26 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[24 Sep 2021 4:45] alex xing
Description:
250834 ==83790== 262,168 bytes in 1 blocks are definitely lost in loss record 11,290 of 11,361
250835 ==83790==    at 0x4C28C20: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
250836 ==83790==    by 0x1FF8A47: ut_allocator<recv_sys_t::Mlog_record>::allocate(unsigned long, recv_sys_t::Mlog_record const*, unsigned int, bool, bool) (ut0new.h:677)
250837 ==83790==    by 0x1FF8B65: allocate (alloc_traits.h:281)
250838 ==83790==    by 0x1FF8B65: _M_allocate (stl_vector.h:170)
250839 ==83790==    by 0x1FF8B65: std::vector<recv_sys_t::Mlog_record, ut_allocator<recv_sys_t::Mlog_record> >::_M_default_append(unsigned long) (vector.tcc:557)
250840 ==83790==    by 0x1FF91D6: resize (stl_vector.h:677)
250841 ==83790==    by 0x1FF91D6: recv_sys_init(unsigned long, bool) (log0recv.cc:878)
250842 ==83790==    by 0x20FDABB: srv_start(bool) (srv0start.cc:2148)
250843 ==83790==    by 0x1F46616: innobase_init_files (ha_innodb.cc:5015)
250844 ==83790==    by 0x1F46616: innobase_ddse_dict_init(dict_init_mode_t, unsigned int, List<dd::Object_table const>*, List<Plugin_tablespace const>*) (ha_innodb.cc:12173)
250845 ==83790==    by 0x1C127FF: dd::bootstrap::DDSE_dict_init(THD*, dict_init_mode_t, unsigned int) (bootstrapper.cc:737)
250846 ==83790==    by 0x1E40C65: dd::upgrade_57::do_pre_checks_and_initialize_dd(THD*) (upgrade.cc:911)
250847 ==83790==    by 0x11EDEE5: handle_bootstrap (bootstrap.cc:323)
250848 ==83790==    by 0x23D33A4: pfs_spawn_thread (pfs.cc:2854)
250849 ==83790==    by 0x4E3D063: start_thread (pthread_create.c:309)
250850 ==83790==    by 0x837A62C: clone (clone.S:111)

How to repeat:
just read the code

Suggested fix:
clear and shrink_to_fit in recv_sys_finish
[24 Sep 2021 4:46] alex xing
a simple patch to describe the fix

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: commit.patch (text/plain), 475 bytes.

[24 Sep 2021 4:59] alex xing
Although this memory will be freed when mysqld is shutdown in srv_shutdown-->recv_sys_close,   
But this structure is not needed during normal running mode, and this chunk of memory can be large( MAX_SAVED_MLOG_RECS = 8 * 1024), so early release is a good option
[24 Sep 2021 5:23] MySQL Verification Team
Hello Alex Xing,

Thank you for the report and contribution.

regards,
Umesh