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 3F2C326200 for ; Sat, 9 Jun 2018 07:13:10 -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 n_1NDdpZJb95 for ; Sat, 9 Jun 2018 07:13:10 -0400 (EDT) Received: from fallback.mail.ru (fallback11.m.smailru.net [94.100.179.26]) (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 DE06726203 for ; Sat, 9 Jun 2018 07:13:09 -0400 (EDT) Received: from [10.161.17.67] (port=41282 helo=smtpng2.m.smailru.net) by fallback11.m.smailru.net with esmtp (envelope-from ) id 1fRaeB-0008Jm-6t for tarantool-patches@freelists.org; Sat, 09 Jun 2018 12:58:59 +0300 From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 03/11] sql: fix leak on CREATE TABLE and resolve self ref Date: Sat, 9 Jun 2018 12:58:43 +0300 Message-Id: <943c156f74cbae0c5a7999584428ece8813fdccc.1528535873.git.kshcherbatov@tarantool.org> 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 +++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 93fca68..72fd5cc 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -1860,8 +1860,12 @@ sql_checks_resolve_space_def_reference(ExprList *expr_list, sql_parser_destroy(&parser); 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); + if (parser.rc != SQL_TARANTOOL_ERROR) { + char *error = tt_static_buf(); + snprintf(error, TT_STATIC_BUF_LEN, "%s", parser.zErrMsg); + diag_set(ClientError, ER_SQL, error); + sqlite3DbFree(db, parser.zErrMsg); + } return -1; } return 0; diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 28e4d7a..3c3c900 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; } -- 2.7.4