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

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

From: Michael Meskes <meskes(at)postgresql(dot)org>
To: Christof Petig <christof(at)petig-baender(dot)de>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]
Date: 2001-09-25 18:15:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-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>

	const char *locale=setlocale(LC_NUMERIC, NULL);   
	printf("%c\n", 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 Meskes
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!

In response to


pgsql-hackers by date

Next:From: Doug McNaughtDate: 2001-09-25 18:56:59
Subject: O_DIRECT and performance
Previous:From: Patrice HédéDate: 2001-09-25 18:14:20
Subject: Re: Unicode combining characters

pgsql-patches by date

Next:From: yasenDate: 2001-09-26 08:29:24
Subject: troubles with setuid patch
Previous:From: Kenneth BeenDate: 2001-09-25 18:12:30
Subject: rtree improvements

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