postgresql/src
Tom Lane 855f0e9247 Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan.
GiST's getNextNearest() function attempts to pfree the previously-returned
tuple if any (that is, scan->xs_hitup in HEAD, or scan->xs_itup in older
branches).  However, if we are rescanning a plan node after ending a
previous scan early, those tuple pointers could be pointing to garbage,
because they would be pointing into the scan's pageDataCxt or queueCxt
which has been reset.  In a debug build this reliably results in a crash,
although I think it might sometimes accidentally fail to fail in
production builds.

To fix, clear the pointer field anyplace we reset a context it might
be pointing into.  This may be overkill --- I think probably only the
queueCxt case is involved in this bug, so that resetting in gistrescan()
would be sufficient --- but dangling pointers are generally bad news,
so let's avoid them.

Another plausible answer might be to just not bother with the pfree in
getNextNearest().  The reconstructed tuples would go away anyway in the
context resets, and I'm far from convinced that freeing them a bit earlier
really saves anything meaningful.  I'll stick with the original logic in
this patch, but if we find more problems in the same area we should
consider that approach.

Per bug #14641 from Denis Smirnov.  Back-patch to 9.5 where this
logic was introduced.

Discussion: https://postgr.es/m/20170504072034.24366.57688@wrigleys.postgresql.org
2017-05-04 13:59:13 -04:00
..
backend Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan. 2017-05-04 13:59:13 -04:00
bin Avoid depending on non-POSIX behavior of fcntl(2). 2017-04-21 15:55:56 -04:00
common pgindent run for 9.6 2016-06-09 18:02:36 -04:00
fe_utils Restore psql's SIGPIPE setting if popen() fails. 2016-12-07 12:39:24 -05:00
include Don't use on-disk snapshots for exported logical decoding snapshot. 2017-04-27 15:29:33 -07:00
interfaces Spelling fixes 2017-03-14 13:45:54 -04:00
makefiles Fix typos in comments and doc 2016-01-28 16:47:36 +09:00
pl plpgsql: Don't generate parallel plans for RETURN QUERY. 2017-03-24 12:39:07 -04:00
port Run the postmaster's signal handlers without SA_RESTART. 2017-04-24 13:00:23 -04:00
template Remove some remains from Alpha support removal 2015-10-29 16:40:14 -04:00
test Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan. 2017-05-04 13:59:13 -04:00
timezone Improve performance of timezone loading, especially pg_timezone_names view. 2017-05-02 21:50:42 -04:00
tools Fix perl thinko in commit fed6df486d 2017-05-02 08:22:45 -04:00
tutorial Update copyright for 2016 2016-01-02 13:33:40 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Install TAP test infrastructure so it's available for extension testing. 2016-09-23 15:50:00 -04:00
Makefile.global.in Document usage of COPT environment variable for adjusting configure flags. 2017-02-17 16:11:02 -05:00
Makefile.shlib Fix typos in comments. 2017-02-06 11:34:15 +02:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00