From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 5ADA921DA0 for ; Wed, 30 Jan 2019 03:59:20 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eagha7l0exmS for ; Wed, 30 Jan 2019 03:59:20 -0500 (EST) Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D8121261A7 for ; Wed, 30 Jan 2019 03:59:19 -0500 (EST) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 4/9] box: fix on_replace_trigger_rollback routine Date: Wed, 30 Jan 2019 11:59:11 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: Kirill Shcherbatov The function on_replace_trigger_rollback in the case of a replace operation rollback was called with an incorrect argument, as a result of which the used memory was freed. --- src/box/alter.cc | 3 ++- test/sql/errinj.result | 24 ++++++++++++++++++++++++ test/sql/errinj.test.lua | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/box/alter.cc b/src/box/alter.cc index ab3dd2e22..eff3524cf 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -3591,7 +3591,8 @@ on_replace_dd_trigger(struct trigger * /* trigger */, void *event) diag_raise(); on_commit->data = old_trigger; - on_rollback->data = new_trigger; + on_rollback->data = + old_tuple == NULL ? new_trigger : old_trigger; new_trigger_guard.is_active = false; } diff --git a/test/sql/errinj.result b/test/sql/errinj.result index c423c8bc6..acce52e8a 100644 --- a/test/sql/errinj.result +++ b/test/sql/errinj.result @@ -205,6 +205,30 @@ box.error.injection.set("ERRINJ_WAL_IO", true) --- - ok ... +t = box.space._trigger:get('T1T') +--- +... +t_new = t:totable() +--- +... +t_new[3]['sql'] = 'CREATE TRIGGER t1t INSERT ON t1 BEGIN INSERT INTO t2 VALUES (2, 2); END;' +--- +... +_ = box.space._trigger:replace(t, t_new) +--- +- error: Failed to write to disk +... +box.error.injection.set("ERRINJ_WAL_IO", false) +--- +- ok +... +_ = box.space._trigger:replace(t, t_new) +--- +... +box.error.injection.set("ERRINJ_WAL_IO", true) +--- +- ok +... box.sql.execute("DROP TRIGGER t1t;") --- - error: Failed to write to disk diff --git a/test/sql/errinj.test.lua b/test/sql/errinj.test.lua index 8378c255c..fc19c859b 100644 --- a/test/sql/errinj.test.lua +++ b/test/sql/errinj.test.lua @@ -75,6 +75,13 @@ box.sql.execute("INSERT INTO t1 VALUES (3, 3);") box.sql.execute("SELECT * from t1"); box.sql.execute("SELECT * from t2"); box.error.injection.set("ERRINJ_WAL_IO", true) +t = box.space._trigger:get('T1T') +t_new = t:totable() +t_new[3]['sql'] = 'CREATE TRIGGER t1t INSERT ON t1 BEGIN INSERT INTO t2 VALUES (2, 2); END;' +_ = box.space._trigger:replace(t, t_new) +box.error.injection.set("ERRINJ_WAL_IO", false) +_ = box.space._trigger:replace(t, t_new) +box.error.injection.set("ERRINJ_WAL_IO", true) box.sql.execute("DROP TRIGGER t1t;") box.error.injection.set("ERRINJ_WAL_IO", false) box.sql.execute("DELETE FROM t1;") -- 2.19.2