From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 740F46EC57; Fri, 15 Oct 2021 01:44:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 740F46EC57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1634251467; bh=CuE3e07fAYhh5r26TVD153waQc3t8lYISy2tvXN0eUI=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=OO+mnTBZTc+MZEkc1U611gk2B7D2clIJozVuhueBS1TUVUsGxQPdzrGeq5K1Z/O4A yVUL9RaMKGsSLUjme8K/MnkYlsXZWlrJdT3WiqV6UUznAlRGmRc4pHBZv1ogzsZ+oi Wlq8woDc8jp3ejBpFA/FlM9Ci5xl2Xhrj/GoE0GM= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id F0F646E1D1 for ; Fri, 15 Oct 2021 01:44:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F0F646E1D1 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mb9SL-0004t5-79; Fri, 15 Oct 2021 01:44:09 +0300 Message-ID: Date: Fri, 15 Oct 2021 00:44:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <170d02abda41079806062247363d898d73202b44.1633713432.git.imeevma@gmail.com> Content-Language: en-US In-Reply-To: <170d02abda41079806062247363d898d73202b44.1633713432.git.imeevma@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9AE9EF867AE584ADA48FDA6574F0672B771BC8658FAF4FA0B182A05F53808504065B87138BA68711226DFB96598C14C586B97DD49BAFE7CD353ABB4A4B93627A7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75263010198C72082EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748744D4CD6EC491D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E708EA82E114E25BEA101C8263DFE9D9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FBDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B50580647984BABFFB5260EC998C1C5CD5CE X-C1DE0DAB: 0D63561A33F958A50212C4EFFFBD14C258671D27D95B4739FFECFB74BD5122FDD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7557E988E9157162368E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3488E5CD2E691F556694B80CDDACB933BE044F413802FF49CDB28B89A83946325AD919F4B077ADD0341D7E09C32AA3244C997AB6017D9DCE01561C7D0EEC0B77C25595C85A795C7BAE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojZCle+NCKLXHUpqSeFmbJNw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D32C571A1529026DA09DB39CA0C7A77613841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 05/21] sql: refactor PRINTF() function X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index 863dbf1c4..f5040fb6e 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -846,6 +846,40 @@ func_octet_length(struct sql_context *ctx, int argc, struct Mem *argv) > mem_set_uint(ctx->pOut, arg->n); > } > > +/** Implementation of the PRINTF() function. */ > +static void > +func_printf(struct sql_context *ctx, int argc, struct Mem *argv) > +{ > + if (argc < 1 || mem_is_null(&argv[0])) > + return; > + if (argc == 1 || !mem_is_str(&argv[0])) { > + struct Mem *mem = ctx->pOut; > + if (mem_copy(mem, &argv[0]) != 0 || mem_to_str(mem) != 0) > + ctx->is_aborted = true; > + return; > + } > + struct PrintfArguments pargs; > + struct StrAccum acc; > + char *format = argv[0].z; > + struct sql *db = sql_get(); > + > + pargs.nArg = argc - 1; > + pargs.nUsed = 0; > + pargs.apArg = sqlDbMallocRawNN(db, (argc - 1) * sizeof(*pargs.apArg)); > + if (pargs.apArg == NULL) { > + ctx->is_aborted = true; > + return; > + } > + for (int i = 1; i < argc; ++i) > + pargs.apArg[i - 1] = &argv[i]; > + sqlStrAccumInit(&acc, db, 0, 0, db->aLimit[SQL_LIMIT_LENGTH]); > + acc.printfFlags = SQL_PRINTF_SQLFUNC; > + sqlXPrintf(&acc, format, &pargs); > + sqlDbFree(db, pargs.apArg); > + if (mem_copy_str(ctx->pOut, sqlStrAccumFinish(&acc), acc.nChar) != 0) It leaks now, because sqlStrAccumFinish is not destroyed. Previously it was 'moved' into the mem via SQL_DYNAMIC. But now you copy it and the original is not freed.