Bug #81714 mysqldump get_view_structure does not free MYSQL_RES in one error path
Submitted: 3 Jun 2016 14:14 Modified: 19 Jun 2017 15:45
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S3 (Non-critical)
Version:5.5+ OS:Any
Assigned to:
Tags: mysqldump

[3 Jun 2016 14:14] Laurynas Biveinis
Description:
A minor code review bug, credit to my colleague Yura Sorokin:

static my_bool get_view_structure(char *table, char* db)
{
  MYSQL_RES  *table_res;
...
  if (mysql_query_with_error_report(mysql, &table_res, query))
...
  if (path)
  {
    if (!(sql_file= open_sql_file_for_table(table, O_WRONLY)))
      DBUG_RETURN(1);

Thus, mysql_free_result is not called here.

How to repeat:
Code review

Suggested fix:
For 5.7, call mysql_free_result there.

For lower versions, backport [1], and call mysql_free_result there.

[1]:

commit 353dbcee4a27b8cfbbd127a28a043bdda764dcf1
Author: Jon Olav Hauglid <jon.hauglid@oracle.com>
Date:   Fri Jun 12 14:55:35 2015 +0200

    Bug#21246627: ASAN: MEMORY LEAK IN PROCESS_SET_GTID_PURGED()
    Bug#21250584: ASAN: MEMORY LEAK IN MYSQLDUMP
    
    Fix three different memory leaks in mysqldump:
    1) Remember to call dynstr_free() on DYNAMIC_STRING.
    2) Remember to call mysql_free_result() on MYSQL_RES.
    3) Remember to call my_free() on string allocated by alloc_query_str().
[5 Jun 2016 14:41] Umesh Shastry
Hello Laurynas,

Thank you for the report and feedback!
Observed in 5.5.49/5.6.30 source as reported.

Thanks,
Umesh
[6 Jun 2017 9:52] Laurynas Biveinis
Bug 81714 fix for 8.0.1 (should apply to lower versions as well)

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

Contribution: bug81714-8.0.1.patch (application/octet-stream, text), 790 bytes.

[19 Jun 2017 15:45] Paul Dubois
Posted by developer:
 
Fixed in 5.6.38, 5.7.20, 8.0.3.

A mysqldump memory leak was fixed. Thanks to Yura Sorokin for the
patch.