Bug #101735 Memory leak in handle_alter_part_end
Submitted: 24 Nov 2020 12:41 Modified: 24 Nov 2020 13:09
Reporter: Zhou Xinjing (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:5.7.32 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, memory leak

[24 Nov 2020 12:41] Zhou Xinjing
Description:
In handle_alter_part_end, part_info is assigned twice from lpt->part_info->get_clone(). 

The value of the pointer part_info is overridden by the second assignment. 

Since there are lots of memory allocations in lpt->part_info->get_clone(), this results in a clear memory leak.

bool handle_alter_part_end(ALTER_PARTITION_PARAM_TYPE *lpt,
                           bool error)
{
  partition_info *part_info= lpt->part_info->get_clone();  /// <<<<<
  THD *thd= lpt->thd;
  TABLE *table= lpt->table;
  DBUG_ENTER("handle_alter_part_end");
  DBUG_ASSERT(table->m_needs_reopen);

  /* First clone the part_info to save the log entries. */
  part_info= lpt->part_info->get_clone();                  /// <<<<<<
...

How to repeat:
Read the code
[24 Nov 2020 12:48] Zhou Xinjing
Fix from Tencent TXSQL Team.

diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 474969a..573107e 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -6784,7 +6784,7 @@ static void reopen_locked_tables(THD *thd)
 bool handle_alter_part_end(ALTER_PARTITION_PARAM_TYPE *lpt,
                            bool error)
 {
-  partition_info *part_info= lpt->part_info->get_clone();
+  partition_info *part_info= NULL;
   THD *thd= lpt->thd;
   TABLE *table= lpt->table;
   DBUG_ENTER("handle_alter_part_end");
[24 Nov 2020 13:09] MySQL Verification Team
Hello Zhou Xinjing,

Thank you for the report and contribution.
Please ensure to re-send the patch via that "contribution" tab. Otherwise we would not be able to accept it.

regards,
Umesh
[24 Nov 2020 13:53] Zhou Xinjing
Simple fix from TXSQL Team of Tencent

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

Contribution: fix.patch (application/octet-stream, text), 497 bytes.