]> granicus.if.org Git - postgresql/commit
Repair double-free in SP-GIST rescan (bug #15378)
authorAndrew Gierth <rhodiumtoad@postgresql.org>
Tue, 11 Sep 2018 17:14:19 +0000 (18:14 +0100)
committerAndrew Gierth <rhodiumtoad@postgresql.org>
Tue, 11 Sep 2018 18:19:50 +0000 (19:19 +0100)
commitc02b56869439281d139d47dae784e3f7cf765f2d
tree1e68f0a79c9d7590e9ddd75e1f99fcd20f9a64a9
parent355fd62e8c73c023b2adc7b04a9cd83336ef7e8a
Repair double-free in SP-GIST rescan (bug #15378)

spgrescan would first reset traversalCxt, and then traverse a
potentially non-empty stack containing pointers to traversalValues
which had been allocated in those contexts, freeing them a second
time. This bug originates in commit ccd6eb49a where traversalValue was
introduced.

Repair by traversing the stack before the context reset; this isn't
ideal, since it means doing retail pfree in a context that's about to
be reset, but the freeing of a stack entry is also done in other
places in the code during the scan so it's not worth trying to
refactor it further. Regression test added.

Backpatch to 9.6 where the problem was introduced.

Per bug #15378; analysis and patch by me, originally from a report on
IRC by user velix; see also PostGIS ticket #4174; review by Alexander
Korotkov.

Discussion: https://postgr.es/m/153663176628.23136.11901365223750051490@wrigleys.postgresql.org
src/backend/access/spgist/spgscan.c
src/test/regress/expected/spgist.out
src/test/regress/sql/spgist.sql