Commit 50014876 authored by Eugene Kosov's avatar Eugene Kosov

MDEV-22074 UBSAN: applying zero offset to null pointer in hash.c

The fix: return fast when no work should be performed.
parent edd7e7c8
...@@ -116,17 +116,23 @@ my_hash_init2(HASH *hash, uint growth_size, CHARSET_INFO *charset, ...@@ -116,17 +116,23 @@ my_hash_init2(HASH *hash, uint growth_size, CHARSET_INFO *charset,
static inline void my_hash_free_elements(HASH *hash) static inline void my_hash_free_elements(HASH *hash)
{ {
uint records= hash->records; uint records= hash->records;
if (records == 0)
return;
/* /*
Set records to 0 early to guard against anyone looking at the structure Set records to 0 early to guard against anyone looking at the structure
during the free process during the free process
*/ */
hash->records= 0; hash->records= 0;
if (hash->free) if (hash->free)
{ {
HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*); HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*);
HASH_LINK *end= data + records; HASH_LINK *end= data + records;
while (data < end) do
{
(*hash->free)((data++)->data); (*hash->free)((data++)->data);
} while (data < end);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment