Re: when to use pfree?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: when to use pfree?
Дата
Msg-id 9813.1162911207@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: when to use pfree?  (Ron Peterson <ron.peterson@yellowbank.com>)
Список pgsql-general
Ron Peterson <ron.peterson@yellowbank.com> writes:
> char*
> tp2cp_palloc( char* stringp, const text* textp ) {
>    int len;
>    len = VARSIZE(textp) - VARHDRSZ;
>    stringp = (char*)palloc( len + 1 );
>    if( ! memcpy( stringp, VARDATA(textp), len ) ) { return NULL; }
>    if( ! memset( stringp + len, '\0', 1 ) ) { return NULL; }
>    return stringp;
> }

That's simply bizarre coding style.  stringp should be a local in
tp2cp_palloc, not a passed parameter that you ignore the value of.

> Which I call like

> otherfunc() {
>   char* rd;
>   if( ! tp2cp_palloc( rd, rand_dev ) )
>   ...

The above does not cause rd to become set in otherfunc().

Had you been using a reasonable set of compiler flags, the compiler
would have warned you that rd was uninitialized in otherfunc().

            regards, tom lane

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

Предыдущее
От: Ron Peterson
Дата:
Сообщение: Re: when to use pfree?
Следующее
От: TJ O'Donnell
Дата:
Сообщение: Re: R and postgres