Re: Memory leak in formatting.c

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Memory leak in formatting.c
Date: 2019-09-03 03:33:10
Message-ID: 20190903033310.GC3765@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2019-09-03 09:54:57 Re: BUG #15977: Inconsistent behavior in chained transactions
Previous Message Konstantin Knizhnik 2019-09-02 16:52:30 Memory leak in formatting.c