diff --git a/doc/src/sgml/indexam.sgml b/doc/src/sgml/indexam.sgml index 1c09bae3955..ef015d48c9e 100644 --- a/doc/src/sgml/indexam.sgml +++ b/doc/src/sgml/indexam.sgml @@ -456,7 +456,8 @@ amendscan (IndexScanDesc scan); End a scan and release resources. The scan struct itself should not be freed, but any locks or pins taken internally by the - access method must be released. + access method must be released, as well as any other memory allocated + by ambeginscan and other scan-related functions. diff --git a/src/backend/access/spgist/spgscan.c b/src/backend/access/spgist/spgscan.c index 8a0d9098c5e..0a7a46364ab 100644 --- a/src/backend/access/spgist/spgscan.c +++ b/src/backend/access/spgist/spgscan.c @@ -236,6 +236,14 @@ spgendscan(PG_FUNCTION_ARGS) MemoryContextDelete(so->tempCxt); + if (so->keyData) + pfree(so->keyData); + + if (so->state.deadTupleStorage) + pfree(so->state.deadTupleStorage); + + pfree(so); + PG_RETURN_VOID(); }