Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org,
	Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v3 02/10] sql: fix leak on CREATE TABLE and resolve self ref
Date: Thu, 14 Jun 2018 20:32:20 +0300	[thread overview]
Message-ID: <ffde2ee57cfc53235492409d791bcf611b685b11.1528997527.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1528997527.git.kshcherbatov@tarantool.org>
In-Reply-To: <cover.1528997527.git.kshcherbatov@tarantool.org>

---
 src/box/sql.c         |  8 ++++----
 src/box/sql/build.c   | 14 +++++---------
 src/box/sql/prepare.c |  1 +
 src/box/sql/trigger.c |  1 +
 4 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index 93fca68..509e581 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -1856,13 +1856,13 @@ sql_checks_resolve_space_def_reference(ExprList *expr_list,
 
 	sql_resolve_self_reference(&parser, &dummy_table, NC_IsCheck, NULL,
 				   expr_list);
-
-	sql_parser_destroy(&parser);
+	int rc = 0;
 	if (parser.rc != SQLITE_OK) {
 		/* Tarantool error may be already set with diag. */
 		if (parser.rc != SQL_TARANTOOL_ERROR)
 			diag_set(ClientError, ER_SQL, parser.zErrMsg);
-		return -1;
+		rc = -1;
 	}
-	return 0;
+	sql_parser_destroy(&parser);
+	return rc;
 }
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 62d687b..606bb69 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -565,7 +565,7 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
 	 */
 	if (!pParse->nested) {
 		if ((v = sqlite3GetVdbe(pParse)) == NULL)
-			goto begin_table_error;
+			goto cleanup;
 		sqlite3VdbeCountChanges(v);
 	}
 
@@ -575,7 +575,7 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
 	if (zName == 0)
 		return;
 	if (sqlite3CheckIdentifierName(pParse, zName) != SQLITE_OK)
-		goto begin_table_error;
+		goto cleanup;
 
 	assert(db->pSchema != NULL);
 	pTable = sqlite3HashFind(&db->pSchema->tblHash, zName);
@@ -587,12 +587,12 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
 		} else {
 			assert(!db->init.busy || CORRUPT_DB);
 		}
-		goto begin_table_error;
+		goto cleanup;
 	}
 
 	pTable = sql_table_new(pParse, zName);
 	if (pTable == NULL)
-		goto begin_table_error;
+		goto cleanup;
 
 	assert(pParse->pNewTable == 0);
 	pParse->pNewTable = pTable;
@@ -608,11 +608,7 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
 	if (!db->init.busy && (v = sqlite3GetVdbe(pParse)) != 0)
 		sql_set_multi_write(pParse, true);
 
-	/* Normal (non-error) return. */
-	return;
-
-	/* If an error occurs, we jump here */
- begin_table_error:
+ cleanup:
 	sqlite3DbFree(db, zName);
 	return;
 }
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 3042cb1..e43fbcb 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -453,5 +453,6 @@ sql_parser_destroy(Parse *parser)
 		db->lookaside.bDisable -= parser->disableLookaside;
 	}
 	parser->disableLookaside = 0;
+	sqlite3DbFree(db, parser->zErrMsg);
 	region_destroy(&parser->region);
 }
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index ea35211..dc9dc46 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -815,6 +815,7 @@ transferParseError(Parse * pTo, Parse * pFrom)
 	} else {
 		sqlite3DbFree(pFrom->db, pFrom->zErrMsg);
 	}
+	pFrom->zErrMsg = NULL;
 }
 
 /*
-- 
2.7.4

  parent reply	other threads:[~2018-06-14 17:32 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-14 17:32 [tarantool-patches] [PATCH v3 00/10] sql: remove Triggers to server Kirill Shcherbatov
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 01/10] box: move db->pShchema init to sql_init Kirill Shcherbatov
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 10/10] sql: VDBE tests for trigger existence Kirill Shcherbatov
2018-06-14 19:27   ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-15 16:21     ` Kirill Shcherbatov
2018-06-18 15:42       ` Vladislav Shpilevoy
2018-06-18 19:22         ` Kirill Shcherbatov
2018-06-19 10:24           ` Vladislav Shpilevoy
2018-06-19 15:12             ` Kirill Shcherbatov
2018-06-19 15:23               ` Vladislav Shpilevoy
2018-06-20  6:38                 ` Kirill Shcherbatov
2018-06-20  8:10                   ` Vladislav Shpilevoy
2018-06-20  8:24                     ` Kirill Shcherbatov
2018-06-14 17:32 ` Kirill Shcherbatov [this message]
2018-06-14 22:46   ` [tarantool-patches] Re: [PATCH v3 02/10] sql: fix leak on CREATE TABLE and resolve self ref n.pettik
2018-06-15  9:25     ` Vladislav Shpilevoy
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 03/10] sql: fix sql len in tarantoolSqlite3RenameTrigger Kirill Shcherbatov
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 04/10] box: port schema_find_id to C Kirill Shcherbatov
2018-06-14 19:27   ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-14 22:46     ` n.pettik
2018-06-15  9:25       ` Vladislav Shpilevoy
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 05/10] sql: refactor sql_expr_compile to return AST Kirill Shcherbatov
2018-06-14 19:27   ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-15 16:21     ` Kirill Shcherbatov
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 06/10] sql: move sqlite3DeleteTrigger to sql.h Kirill Shcherbatov
2018-06-14 19:27   ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 07/10] box: sort error codes in misc.test Kirill Shcherbatov
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 08/10] sql: new _trigger space format with space_id Kirill Shcherbatov
2018-06-14 19:27   ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-15 16:21     ` Kirill Shcherbatov
2018-06-14 17:32 ` [tarantool-patches] [PATCH v3 09/10] sql: move Triggers to server Kirill Shcherbatov
2018-06-14 19:27   ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-15 16:21     ` Kirill Shcherbatov
2018-06-18 15:42       ` Vladislav Shpilevoy
2018-06-18 19:22         ` Kirill Shcherbatov
2018-06-14 17:34 ` [tarantool-patches] Re: [PATCH v3 00/10] sql: remove " Kirill Shcherbatov
2018-06-20  8:35 ` Vladislav Shpilevoy
2018-06-28 15:47   ` n.pettik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ffde2ee57cfc53235492409d791bcf611b685b11.1528997527.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v3 02/10] sql: fix leak on CREATE TABLE and resolve self ref' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox