Re: SPI_cursor_fetch Memory overrun - Mailing list pgsql-hackers

From Tom Lane
Subject Re: SPI_cursor_fetch Memory overrun
Date
Msg-id 8729.1534982927@sss.pgh.pa.us
Whole thread Raw
In response to SPI_cursor_fetch Memory overrun  (Wu Ivy <ivywuyzl@gmail.com>)
List pgsql-hackers
Wu Ivy <ivywuyzl@gmail.com> writes:
>                      fprintf(fp, (i == tupdesc->natts) ? "%s\n" : "%s," , SPI_getvalue(tuple, tupdesc, i));

That (specifically the SPI_getvalue call) is what's leaking memory.
You could improve matters by pfree'ing the result string after each
such call.

Just to add insult to injury, it's also looking up the column datatype's
output function afresh on every call.  There could perhaps be some leakage
involved in those lookups too, though I'd bet the main problem is the
result strings.

            regards, tom lane


pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Query is over 2x slower with jit=on
Next
From: Andres Freund
Date:
Subject: Re: Windows vs C99 (was Re: C99 compliance for src/port/snprintf.c)