Memory leak in formatting.c

Started by Konstantin Knizhnikover 6 years ago2 messagesbugs
Jump to latest
#1Konstantin Knizhnik
k.knizhnik@postgrespro.ru

Memory leak in formatting.c in case of using ICU.
Proposed trivial fix is attached.

--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

formatting.patchtext/x-patch; name=formatting.patchDownload+3-0
#2Michael Paquier
michael@paquier.xyz
In reply to: Konstantin Knizhnik (#1)
Re: Memory leak in formatting.c

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