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 0675D2681F for ; Fri, 15 Jun 2018 12:21:46 -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 d0dFn1YMTKOT for ; Fri, 15 Jun 2018 12:21:45 -0400 (EDT) Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [94.100.177.102]) (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 BCCCF26723 for ; Fri, 15 Jun 2018 12:21:45 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v3 05/10] sql: refactor sql_expr_compile to return AST References: <1259f6bd-8cf0-c9ff-491d-7170c9dd80aa@tarantool.org> From: Kirill Shcherbatov Message-ID: <6c0043ab-6334-9f84-2bfe-975d29b1eed7@tarantool.org> Date: Fri, 15 Jun 2018 19:21:44 +0300 MIME-Version: 1.0 In-Reply-To: <1259f6bd-8cf0-c9ff-491d-7170c9dd80aa@tarantool.org> Content-Type: text/plain; charset=utf-8 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: tarantool-patches@freelists.org Cc: "v.shpilevoy@tarantool.org" > 1. Here parser.region leaks. > 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. diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index e43fbcb..34ee8e3 100644 --- a/src/box/sql/prepare.c +++ b/src/box/sql/prepare.c @@ -454,5 +454,6 @@ sql_parser_destroy(Parse *parser) } parser->disableLookaside = 0; sqlite3DbFree(db, parser->zErrMsg); + sql_expr_delete(db, parser->parsed_expr, false); region_destroy(&parser->region); } diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index d6f5a43..9e4576b 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -559,16 +559,20 @@ sql_expr_compile(sqlite3 *db, const char *expr, int expr_len) char *stmt = (char *)region_alloc(&parser.region, len + 1); if (stmt == NULL) { diag_set(OutOfMemory, len + 1, "region_alloc", "stmt"); - return NULL; + goto end; } sprintf(stmt, "%s%.*s", outer, expr_len, 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 + if (sqlite3RunParser(&parser, stmt, &sql_error) != SQLITE_OK) { + if (parser.rc != SQL_TARANTOOL_ERROR) + diag_set(ClientError, ER_SQL, sql_error); + } else { expression = parser.parsed_expr; + parser.parsed_expr = NULL; + } + +end: sql_parser_destroy(&parser); return expression; }