From 04ba45bd29341e04b40fe43e2c92a7bf2a311638 Mon Sep 17 00:00:00 2001 From: garenchan Date: Tue, 2 Nov 2021 11:44:05 +0800 Subject: [PATCH] Fix memory leak when host_cache_size is 0. --- sql/hostname.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sql/hostname.cc b/sql/hostname.cc index b6cf38d4c3ff..e74a988e29fe 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -199,6 +199,9 @@ static void add_hostname_impl(const char *ip_key, const char *hostname, if (likely(entry == NULL)) { + if (!hostname_cache->size()) + return; + entry= (Host_entry *) malloc(sizeof (Host_entry)); if (entry == NULL) return; @@ -264,8 +267,10 @@ static void add_hostname_impl(const char *ip_key, const char *hostname, entry->m_errors.aggregate(errors); - if (need_add) - hostname_cache->add(entry); + if (need_add && hostname_cache->add(entry)) + { + free(entry); + } return; }