pgsql-bugs(at)postgresql(dot)org writes:
> If I create an external C function consisting of a
> simple loop that inserts 250000 records into a table
> the server process eventually crashes.
The memory leak goes away if you add
SPI_freetuptable(SPI_tuptable);
after the SPI_exec() call.
I am not sure whether to consider this an SPI bug or not. It's possibly
surprising that a non-SELECT query generates an empty tuple table; but
on the other hand, it's hard to say that no non-SELECT query can ever
generate a tuple table. (EXPLAIN is a counterexample, for instance.)
It may be better to document that you should always do
SPI_freetuptable() no matter what kind of query you executed.
regards, tom lane