Re: Memory leak in formatting.c - Mailing list pgsql-bugs

From Michael Paquier
Subject Re: Memory leak in formatting.c
Date
Msg-id 20190903033310.GC3765@paquier.xyz
Whole thread Raw
In response to Memory leak in formatting.c  (Konstantin Knizhnik <k.knizhnik@postgrespro.ru>)
List 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

Attachment

pgsql-bugs by date:

Previous
From: Konstantin Knizhnik
Date:
Subject: Memory leak in formatting.c
Next
From: Stephen Frost
Date:
Subject: Re: BUG #15989: Cluster unable to open as hot standby after SIGKILLduring exclusive backup