Bug #79122 memory leaks when doing INSERT... UPDATE ... prepared statements
Submitted: 4 Nov 2015 15:41 Modified: 10 Nov 2015 17:09
Reporter: Tor Didriksen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Prepared statements Severity:S3 (Non-critical)
Version:5.7.10 OS:Any
Assigned to: CPU Architecture:Any

[4 Nov 2015 15:41] Tor Didriksen
Description:
Problem: memory leaks when doing INSERT... UPDATE ... prepared statements.
Regression source is patch for
    Bug#21908206 MEMORY LEAK ON WINDOWS WHEN SELECT FROM VIEW IN SUBQUERY
Which fixed a regression caused by
    Bug#13901905 - CRASH: INSERT ON DUPLICATE KEY UPDATE READS FREED MEMORY

The patch for Bug#21908206 fixed a leak for LEX objects that were not
properly destroyed.

Solution: clear the std::map for LEX objects thar *are* destroyed.

How to repeat:
./mtr --mem --ps-protocol --valgrind i_main.type_blob-bug13901905             

Suggested fix:
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -3106,6 +3106,7 @@ Prepared_statement::~Prepared_statement()
   if (lex)
   {
     delete lex->result;
+    lex->clear_values_map();
     delete (st_lex_local *) lex;
   }
   free_root(&main_mem_root, MYF(0));
[10 Nov 2015 17:09] Paul Dubois
Noted in 5.7.10, 5.8.0 changelogs.

INSERT ... ON DUPLICATE KEY UPDATE statements could result in a
memory leak when executed as prepared statements.