Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]
От | Karel Zak |
---|---|
Тема | Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it] |
Дата | |
Msg-id | 20010927172655.L31778@zf.jcu.cz обсуждение исходный текст |
Ответ на | Re: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it] (Michael Meskes <meskes@postgresql.org>) |
Список | pgsql-patches |
On Tue, Sep 25, 2001 at 08:15:06PM +0200, Michael Meskes 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 > > 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); > } Because you bad use setlocale(). The setlocale(LC_NUMERIC, NULL) returns actual LC_NUMERIC setting, but your program hasn't some setting, because you don't call: setlocale(LC_NUMERIC, "") or setlocale(LC_NUMERIC, "some_locales") before setlocale(LC_NUMERIC, NULL), try this program: #include <stdio.h> #include <locale.h> #include <stdlib.h> int main() { char *locale; /* create array with locales names */ setlocale(LC_NUMERIC, ""); /* returns data from actual setting */ locale = setlocale(LC_NUMERIC, NULL); printf("%s\n", locale); free((void *) locale); exit(1); } and don't forget set LC_ALL before program runnig. With default locales "C" it is same as with NULL. Previous code: $ export LC_ALL="cs_CZ" $ ./loc cs_CZ $ export LC_ALL="C" $ ./loc C Segmentation fault <-- in free() .... and see locale/setlocale.c in glibc sources :-) Karel -- Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/ C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
В списке pgsql-patches по дате отправления: