when to use pfree?

Поиск
Список
Период
Сортировка
От Ron Peterson
Тема when to use pfree?
Дата
Msg-id 20061107133645.GA9684@yellowbank.com
обсуждение исходный текст
Ответы Re: when to use pfree?
Список pgsql-general
I just encountered a problem with a C function I've been working on
where it broke with the error:

could not find block containing chunk ...

I tracked the problem down to my use of pfree.  Apparently my function
was not happy attempting to return a result that was built using values
that had been pfree'd.  Commenting out the indicated section solved my
problem.

I understand that one of the advantages of palloc is that allocated
memory is automatically returned at some point.  My question is, when
does it make sense to call pfree?  I wouldn't have expected the
variables I free'd below to still be needed, but apparently they were.
So now I'm feeling a little intimidated about using pfree at all.
Should I just save a little wear and tear on my keyboard and forgo the
use of pfree altogether?

   aim = TupleDescGetAttInMetadata( td );
   ht = BuildTupleFromCStrings( aim, vals);

   /* make the tuple into a datum */
   result = HeapTupleGetDatum( ht );

   ...

//   pfree( rd );
//   pfree( vals[0] );
//   pfree( vals[1] );
//   pfree( vals[2] );
//   pfree( vals );

   PG_RETURN_DATUM( result );

TIA

--
Ron Peterson
https://www.yellowbank.com/

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

Предыдущее
От: "Woody Woodring"
Дата:
Сообщение: Re: database name aliases?
Следующее
От: Ron Peterson
Дата:
Сообщение: Re: when to use pfree?