Skip to content

Commit ca00f19

Browse files
committed
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.
1 parent 33e111f commit ca00f19

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/backend/access/gist/gistscan.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,17 @@ gistendscan(PG_FUNCTION_ARGS)
226226
gistfreestack(so->stack);
227227
gistfreestack(so->markstk);
228228
if (so->giststate != NULL)
229+
{
229230
freeGISTstate(so->giststate);
231+
pfree(so->giststate);
232+
}
230233
/* drop pins on buffers -- we aren't holding any locks */
231234
if (BufferIsValid(so->curbuf))
232235
ReleaseBuffer(so->curbuf);
233236
if (BufferIsValid(so->markbuf))
234237
ReleaseBuffer(so->markbuf);
235238
MemoryContextDelete(so->tempCxt);
236-
pfree(scan->opaque);
239+
pfree(so);
237240
}
238241

239242
PG_RETURN_VOID();

0 commit comments

Comments
 (0)