Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2493e2c

Browse files
committed
Fix memory leak in repeated SPGIST index scans.
spgendscan neglected to pfree all the memory allocated by spgbeginscan.It's possible to get away with that in most normal queries, since thememory is allocated in the executor's per-query context which is aboutto get deleted anyway; but it causes severe memory leakage duringcreation or filling of large exclusion-constraint indexes.Also, document that amendscan is supposed to free what ambeginscanallocates. The docs' lack of clarity on that point probably caused thisbug to begin with. (There is discussion of changing that API spec goingforward, but I don't think it'd be appropriate for the back branches.)Per report from Bruno Wolff. It's been like this since the beginning,so back-patch to all active branches.In HEAD, also fix an independent leak caused by commit2a63683(allocating memory during spgrescan instead of spgbeginscan, whichmight be all right if it got cleaned up, but it didn't). And do a bitof code beautification on that commit, too.Discussion:https://postgr.es/m/20181024012314.GA27428@wolff.to
1 parentf107c33 commit2493e2c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

‎doc/src/sgml/indexam.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ amendscan (IndexScanDesc scan);
614614
</programlisting>
615615
End a scan and release resources. The <literal>scan</literal> struct itself
616616
should not be freed, but any locks or pins taken internally by the
617-
access method must be released.
617+
access method must be released, as well as any other memory allocated
618+
by <function>ambeginscan</function> and other scan-related functions.
618619
</para>
619620

620621
<para>

‎src/backend/access/spgist/spgscan.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ spgendscan(IndexScanDesc scan)
240240

241241
MemoryContextDelete(so->tempCxt);
242242
MemoryContextDelete(so->traversalCxt);
243+
244+
if (so->keyData)
245+
pfree(so->keyData);
246+
247+
if (so->state.deadTupleStorage)
248+
pfree(so->state.deadTupleStorage);
249+
250+
pfree(so);
243251
}
244252

245253
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp