Should I free this memory?

Поиск
Список
Период
Сортировка
От Jorge Arévalo
Тема Should I free this memory?
Дата
Msg-id BANLkTikL41Bw8dmNDonLxEE=MKdcohWhoQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Should I free this memory?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Andy Colson
Дата:
Сообщение: Re: Number of Physical I/Os
Следующее
От: ljb
Дата:
Сообщение: What is this doing? SELECT (a,b,c) FROM mytable ...