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 818AA26365 for ; Thu, 14 Jun 2018 13:32:33 -0400 (EDT) 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 urFER9JTk6-2 for ; Thu, 14 Jun 2018 13:32:33 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 317022635D for ; Thu, 14 Jun 2018 13:32:33 -0400 (EDT) From: Kirill Shcherbatov 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 Message-Id: In-Reply-To: References: In-Reply-To: References: 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 Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov --- 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