forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit361844f
committed
Save/restore SPI's global variables in SPI_connect() and SPI_finish().
This patch removes two sources of interference between nominallyindependent functions when one SPI-using function calls another,perhaps without knowing that it does so.Chapman Flack pointed out that xml.c's query_to_xml_internal() expectsSPI_tuptable and SPI_processed to stay valid across datatype outputfunction calls; but it's possible that such a call could involvere-entrant use of SPI. It seems likely that there are similar hazardselsewhere, if not in the core code then in third-party SPI users.Previously SPI_finish() reset SPI's API globals to zeroes/nulls, whichwould typically make for a crash in such a situation. Restoring themto the values they had at SPI_connect() seems like a considerably moreuseful behavior, and it still meets the design goal of not leaving anydangling pointers to tuple tables of the function being exited.Also, cause SPI_connect() to reset these variables to zeroes/nulls aftersaving them. This prevents interference in the opposite direction: it'spossible that a SPI-using function that's only ever been tested standalonecontains assumptions that these variables start out as zeroes. That wasthe case as long as you were the outermost SPI user, but not so much foran inner user. Now it's consistent.Report and fix suggestion by Chapman Flack, actual patch by me.Back-patch to all supported branches.Discussion:https://postgr.es/m/9fa25bef-2e4f-1c32-22a4-3ad0723c4a17@anastigmatix.net1 parentf510412 commit361844f
2 files changed
+39
-9
lines changedLines changed: 33 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
39 | 45 |
| |
40 | 46 |
| |
41 | 47 |
| |
42 |
| - | |
| 48 | + | |
43 | 49 |
| |
44 | 50 |
| |
45 | 51 |
| |
| |||
132 | 138 |
| |
133 | 139 |
| |
134 | 140 |
| |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
135 | 145 |
| |
136 | 146 |
| |
137 | 147 |
| |
| |||
154 | 164 |
| |
155 | 165 |
| |
156 | 166 |
| |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
157 | 176 |
| |
158 | 177 |
| |
159 | 178 |
| |
| |||
176 | 195 |
| |
177 | 196 |
| |
178 | 197 |
| |
179 |
| - | |
| 198 | + | |
180 | 199 |
| |
181 | 200 |
| |
182 |
| - | |
183 |
| - | |
184 |
| - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
185 | 205 |
| |
186 | 206 |
| |
187 | 207 |
| |
| |||
274 | 294 |
| |
275 | 295 |
| |
276 | 296 |
| |
| 297 | + | |
277 | 298 |
| |
278 | 299 |
| |
279 | 300 |
| |
| 301 | + | |
280 | 302 |
| |
281 | 303 |
| |
282 | 304 |
| |
| |||
336 | 358 |
| |
337 | 359 |
| |
338 | 360 |
| |
339 |
| - | |
| 361 | + | |
340 | 362 |
| |
341 | 363 |
| |
342 | 364 |
| |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
343 | 370 |
| |
344 | 371 |
| |
345 | 372 |
| |
346 | 373 |
| |
347 | 374 |
| |
348 |
| - | |
349 |
| - | |
350 |
| - | |
351 | 375 |
| |
352 | 376 |
| |
353 | 377 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
42 | 42 |
| |
43 | 43 |
| |
44 | 44 |
| |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
45 | 51 |
| |
46 | 52 |
| |
47 | 53 |
| |
|
0 commit comments
Comments
(0)