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 9C02526192 for ; Thu, 14 Jun 2018 12:12:36 -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 Hxf3URKNfoKZ for ; Thu, 14 Jun 2018 12:12:36 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 5C68120341 for ; Thu, 14 Jun 2018 12:12:36 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 03/11] sql: fix leak on CREATE TABLE and resolve self ref References: <943c156f74cbae0c5a7999584428ece8813fdccc.1528535873.git.kshcherbatov@tarantool.org> <65a27aff-8334-7651-fc74-d72de9a2a8e4@tarantool.org> From: Kirill Shcherbatov Message-ID: <9a4a8bff-d71f-ac19-73ae-bf52626a6f73@tarantool.org> Date: Thu, 14 Jun 2018 19:12:34 +0300 MIME-Version: 1.0 In-Reply-To: <65a27aff-8334-7651-fc74-d72de9a2a8e4@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" > Why do you need snprintf("%s", str)? It is the same as just 'str'. > is enough to set an error. If zErrMsg was not terminated by zero, snprintf("%s") > would not work as well. But zErrMsg is terminated. I wasn't sure that this diag_set build print string object. It doesn't matter. I've fixed this. > And why do you destroy zErrMsg here? Why not in sql_parser_destroy()? > zErrMsg is struct Parse member. Ok, done. --- 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); } --- 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; } --- 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; }