From: | Jorge Arévalo <jorge(dot)arevalo(at)deimos-space(dot)com> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Should I free this memory? |
Date: | 2011-04-23 01:19:21 |
Message-ID: | BANLkTikL41Bw8dmNDonLxEE=MKdcohWhoQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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(dot)arevalo(at)deimos-space(dot)com
http://es.linkedin.com/in/jorgearevalo80
http://mobility.grupodeimos.com/
http://gis4free.wordpress.com
http://geohash.org/ezjqgrgzz0g
From | Date | Subject | |
---|---|---|---|
Next Message | ljb | 2011-04-23 01:46:19 | What is this doing? SELECT (a,b,c) FROM mytable ... |
Previous Message | Andy Colson | 2011-04-22 21:53:46 | Re: Number of Physical I/Os |