Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]

Поиск
Список
Период
Сортировка
От Michael Meskes
Тема Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]
Дата
Msg-id 20010925201506.A1947@feivel.fam-meskes.de
обсуждение исходный текст
Ответ на Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]  (Christof Petig <christof@petig-baender.de>)
Ответы Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]  (Karel Zak <zakkr@zf.jcu.cz>)
Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-patches
On Mon, Sep 24, 2001 at 09:18:42AM +0200, Christof Petig wrote:
> well at first I could not believe what I was seeing ...

:-)

> Look at the following code (ecpg/lib/execute.c):
>
>    const char *locale=setlocale(LC_NUMERIC, NULL);
>    setlocale(LC_NUMERIC, "C");
> [....]
>    setlocale(LC_NUMERIC, locale);
>
>
> 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

Doesn't look that way on my system. The following programs simply dumps core
in free().

#include <locale.h>
#include <stdio.h>

main()
{
    const char *locale=setlocale(LC_NUMERIC, NULL);

    printf("%c\n", locale);
    free(locale);
}

> setlocale. This is standard conformant and has good reasons. But used as

You're partially right. Standard says "This  string  may  be allocated  in
static storage." So, yes, with your patch we are on the safe side. I just
committed the changes.

Michael

--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!

В списке pgsql-patches по дате отправления:

Предыдущее
От: "Vianen, Jeroen van"
Дата:
Сообщение: Fix for broken JDBC's getColumn() (take 2)
Следующее
От: Benjamin Yu
Дата:
Сообщение: postgresql-7.1.3 pg_ctl password authentication and startup