when to use pfree?

From: Ron Peterson <ron(dot)peterson(at)yellowbank(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: when to use pfree?
Date: 2006-11-07 13:36:45
Message-ID: 20061107133645.GA9684@yellowbank.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Peterson 2006-11-07 13:55:31 Re: when to use pfree?
Previous Message Woody Woodring 2006-11-07 12:48:34 Re: database name aliases?