Skip to content

Commit 72b7570

Browse files
committed
Bug #20720615: GEN_LEX_HASH FAILS WITH MEM.LEAK ERRORS IF COMPILED WITH CLANG-3.5 + ASAN
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).
1 parent e8fb7d7 commit 72b7570

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

sql/gen_lex_hash.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,22 @@ struct hash_lex_struct
9696
{
9797
int first_char;
9898
char last_char;
99+
// union value is undefined if first_char == 0
99100
union{
100-
hash_lex_struct *char_tails;
101-
int iresult;
101+
hash_lex_struct *char_tails; // if first_char > 0
102+
int iresult; // if first_char == -1
102103
};
103104
int ithis;
105+
106+
void destroy()
107+
{
108+
if (first_char <= 0)
109+
return;
110+
for (int i= 0, size= static_cast<uchar>(last_char) - first_char + 1;
111+
i < size; i++)
112+
char_tails[i].destroy();
113+
free(char_tails);
114+
}
104115
};
105116

106117

@@ -119,6 +130,8 @@ class hash_map_info
119130

120131
~hash_map_info()
121132
{
133+
for (int i= 0; i < max_len; i++)
134+
root_by_len[i].destroy();
122135
free(root_by_len);
123136
free(hash_map);
124137
}

0 commit comments

Comments
 (0)