Search Postgresql Archives

when to use pfree?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux