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 059E12975F for ; Mon, 18 Mar 2019 15:34:00 -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 CQGTMUEiyFtb for ; Mon, 18 Mar 2019 15:33:59 -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 AD86B27BB3 for ; Mon, 18 Mar 2019 15:33:59 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 4/7] sql: refactor sql_name_from_token to set diag References: <97dde83dd0ad392cfe47a315ce7ad931cb750a4f.1551265819.git.kshcherbatov@tarantool.org> <4bb2ebb3-dfc7-b95c-cd76-6992baa92128@tarantool.org> From: Vladislav Shpilevoy Message-ID: <9e87fae4-138e-f727-f9fa-8904687d2acc@tarantool.org> Date: Mon, 18 Mar 2019 22:33:57 +0300 MIME-Version: 1.0 In-Reply-To: <4bb2ebb3-dfc7-b95c-cd76-6992baa92128@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: tarantool-patches@freelists.org, Kirill Shcherbatov The diff in your email has nothing to do with sql_name_from_token. You've not sent a new version of that patch, so I did it below with my 2 comments inlined. > commit b052b1b0a43159ac79320d5dca43a201fffa6ab9 > Author: Kirill Shcherbatov > Date: Wed Feb 13 15:15:22 2019 +0300 > > sql: rework sqlNameFromToken to set diag > > Refactored sqlNameFromToken routine as sql_name_from_token and > reworked it to use diag_set in case of memory allocation error. > This change is necessary because the sql_name_from_token body has > a sqlNameFromToken call that will be changed in subsequent > patches. 1. Now, reread that paragraph and fix what is wrong. You do not call sqlNameFromToken from sql_name_from_token. > > Part of #3931 > > diff --git a/src/box/sql/build.c b/src/box/sql/build.c > index d374acb47..1864bd0ad 100644 > --- a/src/box/sql/build.c > +++ b/src/box/sql/build.c > @@ -2981,19 +3001,23 @@ sqlWithAdd(Parse * pParse, /* Parsing context */ > { > sql *db = pParse->db; > With *pNew; > - char *zName; > > - /* Check that the CTE name is unique within this WITH clause. If > - * not, store an error in the Parse structure. > + /* > + * Check that the CTE name is unique within this WITH > + * clause. If not, store an error in the Parse structure. > */ > - zName = sqlNameFromToken(pParse->db, pName); > - if (zName && pWith) { > + char *name = sql_name_from_token(db, pName); > + if (name == NULL) { > + sql_parser_error(pParse); > + return NULL; 2. Leak. sqlWithAdd should delete some structures in a case of OOM. Lines 3035 - 3038. Also, that function does not return NULL on an error - it should return the old value. Otherwise you have a second leak in parse.y:1494. > + } > + if (pWith != NULL) { > int i; > for (i = 0; i < pWith->nCte; i++) { > - if (strcmp(zName, pWith->a[i].zName) == 0) { > + if (strcmp(name, pWith->a[i].zName) == 0) { > sqlErrorMsg(pParse, > - "duplicate WITH table name: %s", > - zName); > + "duplicate WITH table name: %s", > + name); > } > } > }