forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3d13623
committed
Prevent leakage of SPI tuple tables during subtransaction abort.
plpgsql often just remembers SPI-result tuple tables in local variables,and has no mechanism for freeing them if an ereport(ERROR) causes an escapeout of the execution function whose local variable it is. In the originalcoding, that wasn't a problem because the tuple table would be cleaned upwhen the function's SPI context went away during transaction abort.However, once plpgsql grew the ability to trap exceptions, repeatedtrapping of errors within a function could result in significantintra-function-call memory leakage, as illustrated in bug #8279 fromChad Wagner.We could fix this locally in plpgsql with a bunch of PG_TRY/PG_CATCHcoding, but that would be tedious, probably slow, and prone to bugs ofomission; moreover it would do nothing for similar risks elsewhere.What seems like a better plan is to make SPI itself responsible forfreeing tuple tables at subtransaction abort. This patch attacks theproblem that way, keeping a list of live tuple tables within each SPIfunction context. Currently, such freeing is automatic for tuple tablesmade within the failed subtransaction. We might later add a SPI call tomark a tuple table as not to be freed this way, allowing callers to optout; but until someone exhibits a clear use-case for such behavior, itdoesn't seem worth bothering.A very useful side-effect of this change is that SPI_freetuptable() cannow defend itself against bad calls, such as duplicate free requests;this should make things more robust in many places. (In particular,this reduces the risks involved if a third-party extension containsnow-redundant SPI_freetuptable() calls in error cleanup code.)Even though the leakage problem is of long standing, it seems imprudentto back-patch this into stable branches, since it does represent an APIsemantics change for SPI users. We'll patch this in 9.3, but live withthe leakage in older branches.1 parentfd27b99 commit3d13623
File tree
7 files changed
+121
-17
lines changed- doc/src/sgml
- src
- backend/executor
- include/executor
- pl
- plpgsql/src
- plpython
7 files changed
+121
-17
lines changedLines changed: 13 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3934 | 3934 |
| |
3935 | 3935 |
| |
3936 | 3936 |
| |
3937 |
| - | |
3938 |
| - | |
| 3937 | + | |
| 3938 | + | |
3939 | 3939 |
| |
3940 | 3940 |
| |
3941 | 3941 |
| |
| |||
3944 | 3944 |
| |
3945 | 3945 |
| |
3946 | 3946 |
| |
| 3947 | + | |
| 3948 | + | |
| 3949 | + | |
| 3950 | + | |
| 3951 | + | |
| 3952 | + | |
| 3953 | + | |
| 3954 | + | |
| 3955 | + | |
| 3956 | + | |
3947 | 3957 |
| |
3948 | 3958 |
| |
3949 | 3959 |
| |
| |||
3955 | 3965 |
| |
3956 | 3966 |
| |
3957 | 3967 |
| |
3958 |
| - | |
| 3968 | + | |
3959 | 3969 |
| |
3960 | 3970 |
| |
3961 | 3971 |
| |
|
Lines changed: 95 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
126 | 126 |
| |
127 | 127 |
| |
128 | 128 |
| |
| 129 | + | |
129 | 130 |
| |
130 | 131 |
| |
131 | 132 |
| |
| |||
166 | 167 |
| |
167 | 168 |
| |
168 | 169 |
| |
169 |
| - | |
| 170 | + | |
170 | 171 |
| |
171 | 172 |
| |
172 | 173 |
| |
| |||
282 | 283 |
| |
283 | 284 |
| |
284 | 285 |
| |
| 286 | + | |
| 287 | + | |
285 | 288 |
| |
286 | 289 |
| |
287 |
| - | |
288 |
| - | |
289 |
| - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
290 | 315 |
| |
291 | 316 |
| |
292 | 317 |
| |
| |||
1021 | 1046 |
| |
1022 | 1047 |
| |
1023 | 1048 |
| |
1024 |
| - | |
1025 |
| - | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
1026 | 1102 |
| |
1027 | 1103 |
| |
1028 | 1104 |
| |
| |||
1656 | 1732 |
| |
1657 | 1733 |
| |
1658 | 1734 |
| |
| 1735 | + | |
| 1736 | + | |
1659 | 1737 |
| |
1660 | 1738 |
| |
1661 | 1739 |
| |
| |||
1666 | 1744 |
| |
1667 | 1745 |
| |
1668 | 1746 |
| |
1669 |
| - | |
| 1747 | + | |
1670 | 1748 |
| |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
1671 | 1759 |
| |
1672 | 1760 |
| |
1673 | 1761 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
| 16 | + | |
16 | 17 |
| |
17 | 18 |
| |
18 | 19 |
| |
| |||
24 | 25 |
| |
25 | 26 |
| |
26 | 27 |
| |
| 28 | + | |
| 29 | + | |
27 | 30 |
| |
28 | 31 |
| |
29 | 32 |
| |
|
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
26 |
| - | |
| 26 | + | |
27 | 27 |
| |
| 28 | + | |
| 29 | + | |
28 | 30 |
| |
29 | 31 |
| |
30 | 32 |
| |
|
Lines changed: 7 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1202 | 1202 |
| |
1203 | 1203 |
| |
1204 | 1204 |
| |
1205 |
| - | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
1206 | 1212 |
| |
1207 | 1213 |
| |
1208 | 1214 |
| |
|
Lines changed: 0 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
377 | 377 |
| |
378 | 378 |
| |
379 | 379 |
| |
380 |
| - | |
381 |
| - | |
382 | 380 |
| |
383 | 381 |
| |
384 | 382 |
| |
| |||
461 | 459 |
| |
462 | 460 |
| |
463 | 461 |
| |
464 |
| - | |
465 |
| - | |
466 | 462 |
| |
467 | 463 |
| |
468 | 464 |
| |
|
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
439 | 439 |
| |
440 | 440 |
| |
441 | 441 |
| |
442 |
| - | |
443 | 442 |
| |
444 | 443 |
| |
445 | 444 |
| |
|
0 commit comments
Comments
(0)