Re: Leaking memory in text_overlay function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Leaking memory in text_overlay function
Дата
Msg-id 30435.1467470714@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Leaking memory in text_overlay function  (Dirk Rudolph <dirk.rudolph@netcentric.biz>)
Ответы Re: Leaking memory in text_overlay function  (Dirk Rudolph <dirk.rudolph@netcentric.biz>)
Список pgsql-hackers
Dirk Rudolph <dirk.rudolph@netcentric.biz> writes:
> while implementing my own C function, I mentioned that some memory is not freed by the text_overlay function in
varlena.c

By and large, that's intentional.  SQL-called functions normally run
in short-lived memory contexts, so that any memory they don't bother to
pfree will be cleaned up automatically at the end of the tuple cycle.
If we did not follow that approach, there would need to be many thousands
more explicit pfree calls than there are today, and the system would be
net slower overall because multiple retail pfree's are slower than a
MemoryContextReset.

There are places where it's important to avoid leaking memory, certainly.
But I don't think this is one of them, unless you can demonstrate a
scenario with query-lifespan or worse leakage.

> Particularly I mean the both substrings allocated by text_substring (according to the documentation of text_substring
"Theresult is always a freshly palloc'd datum.") and one of the concatenation results. I’m aware of the MemoryContext
beingdeleted in my case but IMHO builtin functions should be memory safe.
 

That is not the project policy.
        regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Docs, backups, and MS VSS
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Bug in batch tuplesort memory CLUSTER case (9.6 only)