Should I free this memory? - Mailing list pgsql-general

From Jorge Arévalo
Subject Should I free this memory?
Date
Msg-id BANLkTikL41Bw8dmNDonLxEE=MKdcohWhoQ@mail.gmail.com
Whole thread Raw
Responses Re: Should I free this memory?
List pgsql-general
Hello,

My C function:

PG_FUNCTION_INFO_V1(my_function);
Datum my_function(PG_FUNCTION_ARGS)
{
MemoryContext old_context;
int * p = NULL;
float f = 0.0;

old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
p = palloc(100);
MemoryContextSwitchTo(old_context);

// do some other stuff

PG_RETURN_FLOAT8(f); // I didn't call pfree(p)
}

Should I free the memory allocated for p? I'm getting memory leaks
when I don't free the memory, and they disappear when I call pfree(p);

I think the response is "yes", I should free the memory (looking at
the results), but I'm not sure why. So, maybe my real doubt is: which
memory context are fcinfo->flinfo->fn_mcxt and old_context? In which
context should I work and why?

Many thanks in advance, and best regards

--
Jorge Arévalo
Internet & Mobilty Division, DEIMOS
jorge.arevalo@deimos-space.com
http://es.linkedin.com/in/jorgearevalo80
http://mobility.grupodeimos.com/
http://gis4free.wordpress.com
http://geohash.org/ezjqgrgzz0g

pgsql-general by date:

Previous
From: Andy Colson
Date:
Subject: Re: Number of Physical I/Os
Next
From: ljb
Date:
Subject: What is this doing? SELECT (a,b,c) FROM mytable ...