forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3f07484
committed
Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan.
GiST's getNextNearest() function attempts to pfree the previously-returnedtuple if any (that is, scan->xs_hitup in HEAD, or scan->xs_itup in olderbranches). However, if we are rescanning a plan node after ending aprevious scan early, those tuple pointers could be pointing to garbage,because they would be pointing into the scan's pageDataCxt or queueCxtwhich has been reset. In a debug build this reliably results in a crash,although I think it might sometimes accidentally fail to fail inproduction builds.To fix, clear the pointer field anyplace we reset a context it mightbe pointing into. This may be overkill --- I think probably only thequeueCxt 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 ingetNextNearest(). The reconstructed tuples would go away anyway in thecontext resets, and I'm far from convinced that freeing them a bit earlierreally saves anything meaningful. I'll stick with the original logic inthis patch, but if we find more problems in the same area we shouldconsider that approach.Per bug #14641 from Denis Smirnov. Back-patch to 9.5 where thislogic was introduced.Discussion:https://postgr.es/m/20170504072034.24366.57688@wrigleys.postgresql.org1 parent20bf7b2 commit3f07484
File tree
4 files changed
+56
-0
lines changed- src
- backend/access/gist
- test/regress
- expected
- sql
4 files changed
+56
-0
lines changedLines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
375 | 375 |
| |
376 | 376 |
| |
377 | 377 |
| |
| 378 | + | |
378 | 379 |
| |
379 | 380 |
| |
380 | 381 |
| |
| |||
642 | 643 |
| |
643 | 644 |
| |
644 | 645 |
| |
| 646 | + | |
645 | 647 |
| |
646 | 648 |
| |
647 | 649 |
| |
| |||
766 | 768 |
| |
767 | 769 |
| |
768 | 770 |
| |
| 771 | + | |
769 | 772 |
| |
770 | 773 |
| |
771 | 774 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
313 | 313 |
| |
314 | 314 |
| |
315 | 315 |
| |
| 316 | + | |
| 317 | + | |
| 318 | + | |
316 | 319 |
| |
317 | 320 |
| |
318 | 321 |
| |
|
Lines changed: 34 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
114 | 114 |
| |
115 | 115 |
| |
116 | 116 |
| |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
117 | 151 |
| |
118 | 152 |
| |
119 | 153 |
| |
|
Lines changed: 16 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
69 | 69 |
| |
70 | 70 |
| |
71 | 71 |
| |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
72 | 88 |
| |
73 | 89 |
| |
74 | 90 |
| |
|
0 commit comments
Comments
(0)