I get nanswers = 16777216, so right off the bat 67MB or so is allocated. Then there's this:
<snippet> /* compute the cross product from right to left */ for (;;) { oneres = (Oid *) palloc0(FUNC_MAX_ARGS * sizeof(Oid)); </snippet>
I'm guessing this gets executed nanswers times. I saw memory usage grow to 880 MB and then killed the process.
I'm not sure of the best way to fix this yet, but I found that when calling the function with argument types matching the prototype perfectly, this code never gets executed.
Actually, adding a "pfree(oneres);" to the end of that for loop plugs the memory leak and allows me to see the error message:
ERROR: Function add_news__test(integer, character varying, timestamp with time zone, character varying, character varying, character varying, character varying, integer, timestamp with time zone, integer, timestamp with time zone, character varying, character varying, character varying, integer, boolean, character varying, character varying, character varying, timestamp with time zone, integer, character varying, character varying, integer) does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
Takes a while to check all 16777216 possibilities though, so I'm still not sure more isn't needed here.
Joe
---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html