Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i4zZU-0004rM-7x for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Sep 2019 03:33:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i4zZT-0004ud-3q for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Sep 2019 03:33:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i4zZR-0004hc-Ir for pgsql-bugs@lists.postgresql.org; Tue, 03 Sep 2019 03:33:30 +0000 Received: from [64.147.123.21] (helo=wout5-smtp.messagingengine.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i4zZO-0001as-Pw for pgsql-bugs@lists.postgresql.org; Tue, 03 Sep 2019 03:33:28 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 80E07944; Mon, 2 Sep 2019 23:33:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 02 Sep 2019 23:33:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=RR/cgRqXlC9FPiQ2moWCluX+DS/ zSIGG5NOYlcXZNIk=; b=Etkl01W6JNBUZ7sxMaJbpkqaRSFNbQvW78yvTXPxQG2 ZXYzW5h83ImFeHxDxEBM1YQJK1ood94MgnYKM/5BBAuR/JZYueh9pHsG95JiRomX dSrA7oHe2vK+njH0jrg16yZL+e8cMwQQTuP0K5wxbQWZ0YgB2VWWHsIWxDRit9zV UnxtanIcjUGm6a0DtvT7oCQO+xQUDzT5ofZy/6t/N1h+iehYy6sMqqOK30Juh+hu 4kXtoAIPCjEaiLewOxyjJgegtNQYVjvEh2CRx9Oh1hrM0bF3AcJ7LE7XIWWoBd3D Mj7XuCbDKmP96qB2wyO+bPy+qTL/iU6Zki6kSqbCExA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=RR/cgR qXlC9FPiQ2moWCluX+DS/zSIGG5NOYlcXZNIk=; b=IRm6cAN/yvdpHJmBmumq8H OAp7QXA3mrLUbx3riOswIvlXpHXrUd3wG51PSnd2iKw1MDVH9iWhA4kzhvDYzBbN UZa1l+PeZllUFHzzOiTotp4ojfv7i6RmeFpiWg0ka0nHbQ+QnvUkWhKVkAFT4881 Yx9g3nx4Ol68NwAlWRFN+8HSaMu0lPbzns5gQLNis6opQ+4pXCnTA6Q/zDnOUGzn ivGFBhU8x9BF0pJeG7qeWAuKX3Ja4MjE+7R034TQksGcVIkonLgyytY1MSOexurM TCL1T7IMW9WrheVEMcsrhLCBXlh+HQRisMZCp+3qNLQA2SP44f+GkOY9mbwY+cAA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudejuddgjedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepuddukedrvdeguddrvdehuddrgeenucfrrghrrghm pehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlhhush htvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (mp76f1fb04.ap.nuro.jp [118.241.251.4]) by mail.messagingengine.com (Postfix) with ESMTPA id 5A1EC8005C; Mon, 2 Sep 2019 23:33:13 -0400 (EDT) Date: Tue, 3 Sep 2019 12:33:10 +0900 From: Michael Paquier To: Konstantin Knizhnik Cc: pgsql-bugs@lists.postgresql.org Subject: Re: Memory leak in formatting.c Message-ID: <20190903033310.GC3765@paquier.xyz> References: <94c0ad0a-cbc2-e4a3-7829-2bdeaf9146db@postgrespro.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="iVCmgExH7+hIHJ1A" Content-Disposition: inline In-Reply-To: <94c0ad0a-cbc2-e4a3-7829-2bdeaf9146db@postgrespro.ru> X-Host-Lookup-Failed: Reverse DNS lookup failed for 64.147.123.21 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --iVCmgExH7+hIHJ1A Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 02, 2019 at 07:52:30PM +0300, Konstantin Knizhnik wrote: > Memory leak in formatting.c in case of using ICU. > Proposed trivial fix is attached. Right. Those three code paths can be triggered with an ICU collation. I can see for example that patterns like the following one consume more memory unpatched: create collation german_phonebook (provider = icu, locale = 'de-u-co-phonebk'); create table german_phones (number text collate german_phonebook); insert into german_phones select repeat('AB', 1000) || repeat('CD', 1000) from generate_series(1,1000000); select count(lower(number)) from german_phones, generate_series(1,10000000); valgrind does not complain in this scenario. Anyway, we cannot assume that the callers of str_tolower & co are able to do a correct cleanup of the memory context where the allocation happened, so I have applied your patch and back-patched down to 10 where the issue has been introduced. Thanks, Konstantin! -- Michael --iVCmgExH7+hIHJ1A Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl1t3vYACgkQnvQgOdby QH3Pbw/+IXfYniKcyZf/moR++aflx4NucCj1v+tLnSRJ5R1ybS7SvrCjQbMEavdD Rpc0xea8RVV7fbFxc9Fz6LYzqOmbQaogujqeCEwUyBLQGdiaYyfs8zgFlTGrIcMO kFiOhDaKppcTl09wTCwexyS1mp7xI65CTtIjCAhry/WbVaiKuqoxSMqmaK8O1+Ja 6m9Ox53cvnXpCUeYITLBV/SU4J9clJiGF9pfDcmlw3qySdRqwfE9NjnOAdp1b0so lVUNmXELNS6Hho/lHMji0J/4ygmFlKujmKFgr+9B1qKh0Hl4bQUVhLdGUaZGssfP 5Ig+9tq3/7ikOO1GO4vBMEau3puyxwGZ21xLaD6Lv+HhI+f6YjtRJfLtinQdgcnU TJDSLVYGvk9xh+rDUBTcU13edcEvC2WvBE1/5MDyUFlpqCxr50wrBewGoufBC9GT F+0KjawfAyplq+Ak10hiCArMTR02Arv5ot3pKaMRFwbIWc2BwNyTqcWuh1lO5oiH qqI2mnA+fToQNlfSEOu6IG7oMSGAsn9WZXhMWHM3FBiydtG8Q5FboVTUHYKRsSsC 3w3iem0ZTsKBOEUFugIuYAuvzASW36Dlm0bHz4O4ls4gbvd5YiESKNq+T4yXTk6S 0gJuH7bPY1QOWE+YIfAh1Jl4yPifpWgvnfjn7Oai+/65oyursmI= =fdxJ -----END PGP SIGNATURE----- --iVCmgExH7+hIHJ1A--