Bug #114829 Scoped_heap incorrect usage may have memory leak
Submitted: 30 Apr 21:15 Modified: 3 May 5:08
Reporter: david zhang Email Updates:
Status: Verified 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 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 5:08] MySQL Verification Team
Hello david zhang,

Thank you for the report and feedback.

regards,
Umesh
[6 Jun 9:21] Niksa Skeledzija
Posted by developer:
 
I fixed this issue as part of https://mybug.mysql.oraclecorp.com/orabugs/site/bug.php?id=35988311, so this is a duplicate. Closing as such.