Bug #80014 mysql build fails, memory leak in gen_lex_hash, clang address sanitizer
Submitted: 16 Jan 2016 17:51 Modified: 21 Sep 2016 21:29
Reporter: Richard Prohaska Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.6.28 OS:Ubuntu (14.04)
Assigned to: CPU Architecture:Any

[16 Jan 2016 17:51] Richard Prohaska
Description:
build of mysql fails 

==5141==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 13792 byte(s) in 1 object(s) allocated from:
    #0 0x4b3460 in realloc /home/rfp/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:61
    #1 0x4e3f18 in add_struct_to_map(hash_lex_struct*) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:239:20
    #2 0x4e41b7 in add_structs_to_map(hash_lex_struct*, int) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:261:5
    #3 0x4e4227 in add_structs_to_map(hash_lex_struct*, int) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:265:7
    #4 0x4e4227 in add_structs_to_map(hash_lex_struct*, int) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:265:7
    #5 0x4e4227 in add_structs_to_map(hash_lex_struct*, int) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:265:7
    #6 0x4e4227 in add_structs_to_map(hash_lex_struct*, int) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:265:7
    #7 0x4e4227 in add_structs_to_map(hash_lex_struct*, int) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:265:7
    #8 0x4e4227 in add_structs_to_map(hash_lex_struct*, int) /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:265:7
    #9 0x4e463e in print_find_structs() /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:310:3
    #10 0x4e4963 in main /home/rfp/projects/mysql.56/mysql-server/sql/gen_lex_hash.cc:394:3
    #11 0x2b2d86a76ec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287

SUMMARY: AddressSanitizer: 13792 byte(s) leaked in 1 allocation(s).

How to repeat:
git checkout -b 5.6 git@github.com:mysql/mysql-server
mkdir build install
cd build
CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_ASAN=ON ../mysql-server

Suggested fix:
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index bbbcf1b..12525fa 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -311,6 +311,7 @@ void print_find_structs()
   set_links(root_by_len,max_len);
   print_hash_map("sql_functions_map");
 
+  free(hash_map);
   hash_map= 0;
   size_hash_map= 0;
 
@@ -319,6 +320,9 @@ void print_find_structs()
   add_structs_to_map(root_by_len2,max_len2);
   set_links(root_by_len2,max_len2);
   print_hash_map("symbols_map");
+  free(hash_map);
+  hash_map= 0;
+  size_hash_map= 0;
 }
[18 Jan 2016 7:45] Umesh Shastry
Hello Richard Prohaska,

Thank you for the report and contribution.
In order to submit contributions you must first sign the Oracle Contribution Agreement (OCA). For additional information please check http://www.oracle.com/technetwork/community/oca-486395.html.
If you have any questions, please contact the MySQL community team.

Thanks,
Umesh
[18 Aug 2016 11:40] Roel Van de Paar
Could we please have this bug fixed?
[21 Sep 2016 17:31] Paul Dubois
Posted by developer:
 
Noted in 5.6.34 changelog.

Compiling using Clang 3.5 or higher with AddressSanitizer (ASAN)
enabled caused the gen_lex_hash utility to abort on Clang
LeakSanitizer memory leak check failures.
[21 Sep 2016 21:29] Richard Prohaska
I dont understand that status of this bug report.  Is the bug fixed or documented away?
[22 Sep 2016 5:53] Laurynas Biveinis
The changelog entry applies to GCC too, not only clang.
[22 Sep 2016 5:54] Tor Didriksen
Posted by developer:
 
commit cb04f126c6373950f07e75ac2462182c4acad428
Author: Tor Didriksen <tor.didriksen@oracle.com>
Date:   Fri Sep 2 12:46:33 2016 +0200

    Bug#22558597 MYSQL BUILD FAILS, MEMORY LEAK IN GEN_LEX_HASH, CLANG ADDRESS SANITIZER
    
    If we use clang-3.5+ instead of gcc and enable its AddessSanitizer (ASAN),
    the gen_lex_hash utility aborts on clang's LeakSanitizer memory leak
    checks.
    
    This patch adds memory deallocation to gen_lex_hash.cc to make
    LeakSanitizer happy (normally this is superfluous, since gen_lex_has is
    a compile-time utility, and OS does the job itself).
    
    Note: for for 5.6 only. Fixed in 5.7 and up by patch for Bug#20720615
[28 Sep 2016 15:00] Paul Dubois
Posted by developer:
 
Noted in 5.6.35 (not 5.6.34) changelog.

Richard: Fixed.