Skip site navigation (1) Skip section navigation (2)

Re: [PATCHES] Problem with setlocale (found in libecpg) [accessing a

From: Christof Petig <christof(at)petig-baender(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCHES] Problem with setlocale (found in libecpg) [accessing a
Date: 2001-09-27 07:26:12
Message-ID: 3BB2D494.3EF2381@petig-baender.de (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Tom Lane wrote:

> >> Well at least on glibc-2.2 it seems that setlocale retuns a pointer to
> >> malloced memory, and frees this pointer on subsequent calls to
> >> setlocale.
> >> So I would kindly ask you to take a second look at every invokation of
> >> setlocale.
>
> I looked around, and am worried about the behavior of PGLC_current()
> in src/backend/utils/adt/pg_locale.c.  It doesn't change locale but
> does retrieve several successive setlocale() results.  Does that work
> in glibc?

Well actually I did not check glibc's source code. But I tried to run my
program with efence and it aborted in execute.c

[   locale=setlocale(LC_NUMERIC,NULL);
    setlocale(LC_NUMERIC,"C");
     ...
    setlocale(LC_NUMERIC,locale);   // access to already freed memory
(locale)
]

So my best guess is that setlocale
- uses a malloced memory for return (which copes best with variable length
strings)
- frees this on a subsequent calls and allocates a new one.

Yes, I'm worried about PGLC_current(), too.
IMHO we should definitely copy the result to a malloced area.
Does the current solution work with static storage (old libcs?)? The last
call would overwrite the first result, wouldn't it?

Christof



In response to

Responses

pgsql-hackers by date

Next:From: Hannu KrosingDate: 2001-09-27 08:00:41
Subject: Re: multibyte performance
Previous:From: Myron ScottDate: 2001-09-27 05:24:29
Subject: Re: Spinlock performance improvement proposal

pgsql-patches by date

Next:From: Karel ZakDate: 2001-09-27 08:49:24
Subject: Re: [PATCHES] Problem with setlocale (found in libecpg) [accessing a
Previous:From: Tom LaneDate: 2001-09-27 04:08:29
Subject: Re: Problem with setlocale (found in libecpg) [accessing a

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group