pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Memory leak in formatting.c
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2019-09-03 3a54eb1a38 5380719f93 f967a1fda8 604d20679e  Fix memory leak with lower, upper and initcap with ICU-provided collations
* Memory leak in formatting.c
@ 2019-09-02 16:52 Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
  2019-09-03 03:33 ` Re: Memory leak in formatting.c Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 2+ messages in thread

From: Konstantin Knizhnik @ 2019-09-02 16:52 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

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.patch (text/x-patch, 922B) download diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index b3115e4..755ca6e 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -1584,6 +1584,7 @@ str_tolower(const char *buff, size_t nbytes, Oid collid) &buff_conv, buff_uchar, len_uchar); icu_from_uchar(&result, buff_conv, len_conv); pfree(buff_uchar); + pfree(buff_conv); } else #endif @@ -1707,6 +1708,7 @@ str_toupper(const char *buff, size_t nbytes, Oid collid) &buff_conv, buff_uchar, len_uchar); icu_from_uchar(&result, buff_conv, len_conv); pfree(buff_uchar); + pfree(buff_conv); } else #endif @@ -1831,6 +1833,7 @@ str_initcap(const char *buff, size_t nbytes, Oid collid) &buff_conv, buff_uchar, len_uchar); icu_from_uchar(&result, buff_conv, len_conv); pfree(buff_uchar); + pfree(buff_conv); } else #endif
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: Memory leak in formatting.c
  2019-09-02 16:52 Memory leak in formatting.c Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
@ 2019-09-03 03:33 ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Paquier @ 2019-09-03 03:33 UTC (permalink / raw)
  To: Konstantin Knizhnik <k.knizhnik@postgrespro.ru>; +Cc: pgsql-bugs@lists.postgresql.org

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

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-09-03 03:33 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02 16:52 Memory leak in formatting.c Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
2019-09-03 03:33 ` Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox