Re: Leaking memory in text_overlay function - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Leaking memory in text_overlay function
Date
Msg-id 30435.1467470714@sss.pgh.pa.us
Whole thread Raw
In response to Leaking memory in text_overlay function  (Dirk Rudolph <dirk.rudolph@netcentric.biz>)
Responses Re: Leaking memory in text_overlay function  (Dirk Rudolph <dirk.rudolph@netcentric.biz>)
List 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 by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Docs, backups, and MS VSS
Next
From: Tom Lane
Date:
Subject: Re: Bug in batch tuplesort memory CLUSTER case (9.6 only)