From 0a6cc28500b7a8db7a27cbd0d75e18837fb2e367 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 16 Sep 2011 04:27:49 -0400
Subject: [PATCH] gistendscan() forgot to free so->giststate.

This oversight led to a massive memory leak --- upwards of 10KB per tuple
--- during creation-time verification of an exclusion constraint based on a
GIST index.  In most other scenarios it'd just be a leak of 10KB that would
be recovered at end of query, so not too significant; though perhaps the
leak would be noticeable in a situation where a GIST index was being used
in a nestloop inner indexscan.  In any case, it's a real leak of long
standing, so patch all supported branches.  Per report from Harald Fuchs.
---
 src/backend/access/gist/gistscan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c
index 97a19aa2ac9..5071d46150e 100644
--- a/src/backend/access/gist/gistscan.c
+++ b/src/backend/access/gist/gistscan.c
@@ -240,6 +240,7 @@ gistendscan(PG_FUNCTION_ARGS)
 	GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
 
 	freeGISTstate(so->giststate);
+	pfree(so->giststate);
 	MemoryContextDelete(so->queueCxt);
 	MemoryContextDelete(so->tempCxt);
 	pfree(so->tmpTreeItem);
-- 
GitLab