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 6D57625B1A for ; Wed, 13 Jun 2018 14:53:49 -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 5S7arfd_KnbM for ; Wed, 13 Jun 2018 14:53:49 -0400 (EDT) Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (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 2A3D4259A5 for ; Wed, 13 Jun 2018 14:53:49 -0400 (EDT) From: Vladislav Shpilevoy 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> Message-ID: <65a27aff-8334-7651-fc74-d72de9a2a8e4@tarantool.org> Date: Wed, 13 Jun 2018 21:53:46 +0300 MIME-Version: 1.0 In-Reply-To: <943c156f74cbae0c5a7999584428ece8813fdccc.1528535873.git.kshcherbatov@tarantool.org> 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 patch! See 1 comment below. On 09/06/2018 12:32, Kirill Shcherbatov wrote: > --- > 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); Why do you need snprintf("%s", str)? It is the same as just 'str'. diag_set(ClientError, ER_SQL, parser.zErrMsg); is enough to set an error. If zErrMsg was not terminated by zero, snprintf("%s") would not work as well. But zErrMsg is terminated. And why do you destroy zErrMsg here? Why not in sql_parser_destroy()? zErrMsg is struct Parse member. > + sqlite3DbFree(db, parser.zErrMsg); > + } > return -1; > } > return 0;