From 29dbb23fb7ac3b10e70e4c5f99dcedab91af85ba Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 24 May 2018 15:18:09 +0300 Subject: MDEV-16093 Memory leak with triggers Problem was that blob memory allocated in Table_trigger_list was not properly freed --- mysql-test/r/trigger.result | 13 ++++++++++++- mysql-test/t/trigger.test | 14 +++++++++++++- sql/sql_trigger.cc | 6 ++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 8455450e294..8852a622251 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -2306,4 +2306,15 @@ CREATE TABLE t1 (i INT); insert into t2 value (2); DROP VIEW v1; DROP TABLE t1,t2,t3; -End of 10.1 tests. +# +# MDEV-16093 +# Assertion `global_status_var.global_memory_used == 0' failed or +# bytes lost after inserting into table with non-null blob and trigger +# +CREATE TABLE t1 (b BLOB NOT NULL); +CREATE TRIGGER tr BEFORE UPDATE ON t1 FOR EACH ROW BEGIN END; +INSERT INTO t1 VALUES ('foo'); +DROP TABLE t1; +# +# End of 10.1 tests. +# diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index ff6f38b719d..a6d4107e591 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -2656,5 +2656,17 @@ insert into t2 value (2); DROP VIEW v1; DROP TABLE t1,t2,t3; +--echo # +--echo # MDEV-16093 +--echo # Assertion `global_status_var.global_memory_used == 0' failed or +--echo # bytes lost after inserting into table with non-null blob and trigger +--echo # + +CREATE TABLE t1 (b BLOB NOT NULL); +CREATE TRIGGER tr BEFORE UPDATE ON t1 FOR EACH ROW BEGIN END; +INSERT INTO t1 VALUES ('foo'); +DROP TABLE t1; ---echo End of 10.1 tests. +--echo # +--echo # End of 10.1 tests. +--echo # diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 293a4c17156..bbcc75718a3 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -614,6 +614,7 @@ end: #endif /* WITH_WSREP */ } + /** Build stmt_query to write it in the bin-log and get the trigger definer. @@ -1061,6 +1062,11 @@ Table_triggers_list::~Table_triggers_list() for (int j= 0; j < (int)TRG_ACTION_MAX; j++) delete bodies[i][j]; + /* Free blobs used in insert */ + if (record0_field) + for (Field **fld_ptr= record0_field; *fld_ptr; fld_ptr++) + (*fld_ptr)->free(); + if (record1_field) for (Field **fld_ptr= record1_field; *fld_ptr; fld_ptr++) delete *fld_ptr; -- cgit v1.2.1