Bug #114829 Scoped_heap incorrect usage may have memory leak
Submitted: 30 Apr 2024 21:15 Modified: 8 Aug 11:55
Reporter: david zhang Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: memory leak

[30 Apr 2024 21:15] david zhang
Description:
in btr0btr.cc

Change-Id: Id131b86fe39daece93a9d08150731c04ab552193

void BFT::children_to_visit(buf_block_t *block) {
  if (block->is_leaf()) {
    return;
  }
  Scoped_heap scoped_heap{};
  mem_heap_t *heap = scoped_heap.get();
  ulint *offsets = nullptr;
  page_cur_t cur;
  page_cur_set_before_first(block, &cur);
  page_cur_move_to_next(&cur);
  while (!page_cur_is_after_last(&cur)) {
    rec_t *rec = page_cur_get_rec(&cur);
    offsets = rec_get_offsets(rec, m_index, offsets, ULINT_UNDEFINED,
                              UT_LOCATION_HERE, &heap);
    const page_no_t child = btr_node_ptr_get_child_page_no(rec, offsets);
    m_pages_to_visit.push_back(child);
    page_cur_move_to_next(&cur);
  }
}

heap is nullptr at init, then a heap is allocated by rec_get_offsets(), then it is leaked since Scoped_heap is not aware of its allocation.

How to repeat:
Manual inspection.

Suggested fix:
  Scoped_heap local_heap(2048, UT_LOCATION_HERE);

or use some other reasonable init values instead of default ctor.
[3 May 2024 5:08] MySQL Verification Team
Hello david zhang,

Thank you for the report and feedback.

regards,
Umesh
[8 Aug 11:56] MySQL Verification Team
Fixed by bug #35988311 .

Fixed as of the upcoming MySQL Server 9.1.0 release, and here's the proposed changelog entry from the documentation team:

Fixed a memory leak in the bulk loader.

Thank you for the bug report.