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 57CC824508 for ; Thu, 14 Jun 2018 15:27:17 -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 1WUKu9Tx46vB for ; Thu, 14 Jun 2018 15:27:17 -0400 (EDT) Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (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 99556261FD for ; Thu, 14 Jun 2018 15:27:16 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v3 05/10] sql: refactor sql_expr_compile to return AST References: From: Vladislav Shpilevoy Message-ID: <1259f6bd-8cf0-c9ff-491d-7170c9dd80aa@tarantool.org> Date: Thu, 14 Jun 2018 22:27:14 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: Kirill Shcherbatov , tarantool-patches@freelists.org Thanks for the fixes! See 2 comments below. Besides, I have pushed other review fixes as a separate commit. Please, look and squash. On 14/06/2018 20:32, Kirill Shcherbatov wrote: > --- > src/box/alter.cc | 6 +++--- > src/box/sql.c | 5 +++-- > src/box/sql.h | 9 ++++----- > src/box/sql/tokenize.c | 32 +++++++++++++++++++------------- > 4 files changed, 29 insertions(+), 23 deletions(-) > > diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c > index 42c70a2..d84a840 100644 > --- a/src/box/sql/tokenize.c > +++ b/src/box/sql/tokenize.c > @@ -550,19 +555,20 @@ sql_expr_compile(sqlite3 *db, const char *expr, int expr_len, > sql_parser_create(&parser, db); > parser.parse_only = true; > > + struct Expr *expression = NULL; > char *stmt = (char *)region_alloc(&parser.region, len + 1); > if (stmt == NULL) { > diag_set(OutOfMemory, len + 1, "region_alloc", "stmt"); > - return -1; > + return NULL; 1. Here parser.region leaks. > } > sprintf(stmt, "%s%.*s", outer, expr_len, expr); > > - char *unused; > - if (sqlite3RunParser(&parser, stmt, &unused) != SQLITE_OK) { > - diag_set(ClientError, ER_SQL_EXECUTE, expr); > - return -1; > - } > - *result = parser.parsed_expr; > + char *sql_error; > + if (sqlite3RunParser(&parser, stmt, &sql_error) != SQLITE_OK && > + parser.rc != SQL_TARANTOOL_ERROR) > + diag_set(ClientError, ER_SQL, sql_error); > + else > + expression = parser.parsed_expr; 2. If a TARANTOOL_ERROR has occurred and parsed_expr had been set before it, then you return not NULL, but should return NULL. And you should destroy the expression. Looks like it was a leak before your patch. Lets always delete all the parsed expressions in parser_destroy (here only parsed_expr is). And in this function on success nullify this member before destroy. > sql_parser_destroy(&parser); > - return 0; > + return expression; > } >