diff options
author | Oleg Smirnov <olernov@gmail.com> | 2022-10-01 19:37:25 +0400 |
---|---|---|
committer | Oleg Smirnov <olernov@gmail.com> | 2022-10-02 09:23:58 +0400 |
commit | bcaf00f9e52d9b22879f5b4e5c07dc27af7e6bb5 (patch) | |
tree | e9c2cded69eb848d33d085f88316e897b5b47882 /sql/sql_select.cc | |
parent | 2f37c2dfa1a2050e122e026ec0801bba9ba98cfd (diff) | |
download | mariadb-git-bb-10.11-MDEV-29624.tar.gz |
MDEV-29624 Fix memory leak on pushdown of derived tablebb-10.11-MDEV-29624
Deallocation of TABLE_LIST::dt_handler and TABLE_LIST::pushdown_derived
was performed in multiple places if code. This not only made the code
more difficult to maintain but also lead to memory leaks when
dt_handler and pushdown_derived were allocated but actual pushdown
of the derived table did not take place due to the whole embedding
unit pushdown.
This commit puts deallocation of TABLE_LIST::dt_handler and
TABLE_LIST::pushdown_derived to the single point - JOIN::cleanup().
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 47237d94d87..7013cb2301c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -69,6 +69,7 @@ #include "my_json_writer.h" #include "opt_trace.h" #include "create_tmp_table.h" +#include "derived_handler.h" /* A key part number that means we're using a fulltext scan. @@ -14382,6 +14383,7 @@ void JOIN_TAB::cleanup() delete filesort->select; delete filesort; filesort= NULL; + /* Skip non-existing derived tables/views result tables */ if (table && (table->s->tmp_table != INTERNAL_TMP_TABLE || table->is_created())) @@ -14882,11 +14884,11 @@ void JOIN::cleanup(bool full) delete pushdown_query; pushdown_query= 0; - if (!join_tab) + List_iterator<TABLE_LIST> li(*join_list); + TABLE_LIST *table_ref; + while ((table_ref= li++)) { - List_iterator<TABLE_LIST> li(*join_list); - TABLE_LIST *table_ref; - while ((table_ref= li++)) + if (!join_tab) { if (table_ref->table && table_ref->jtbm_subselect && @@ -14896,6 +14898,13 @@ void JOIN::cleanup(bool full) table_ref->table= NULL; } } + if (table_ref->pushdown_derived) + { + delete table_ref->pushdown_derived; + table_ref->pushdown_derived= NULL; + } + delete table_ref->dt_handler; + table_ref->dt_handler= NULL; } } /* Restore ref array to original state */ @@ -28516,12 +28525,6 @@ bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) result, unit, first); } - if (unit->derived && unit->derived->pushdown_derived) - { - delete unit->derived->pushdown_derived; - unit->derived->pushdown_derived= NULL; - } - DBUG_RETURN(res || thd->is_error()); } |