forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1f67078
committed
Add OpenTransientFile, with automatic cleanup at end-of-xact.
Files opened with BasicOpenFile or PathNameOpenFile are not automaticallycleaned up on error. That puts unnecessary burden on callers that only wantto keep the file open for a short time. There is AllocateFile, but thatreturns a buffered FILE * stream, which in many cases is not the nicest APIto work with. So add function called OpenTransientFile, which returns aunbuffered fd that's cleaned up like the FILE* returned by AllocateFile().This plugs a few rare fd leaks in error cases:1. copy_file() - fixed by by using OpenTransientFile instead of BasicOpenFile2. XLogFileInit() - fixed by adding close() calls to the error cases. Can't use OpenTransientFile here because the fd is supposed to persist over transaction boundaries.3. lo_import/lo_export - fixed by using OpenTransientFile instead of PathNameOpenFile.In addition to plugging those leaks, this replaces many BasicOpenFile() callswith OpenTransientFile() that were not leaking, because the code meticulouslyclosed the file on error. That wasn't strictly necessary, but IMHO it's goodfor robustness.The same leaks exist in older versions, but given the rarity of the issues,I'm not backpatching this. Not yet, anyway - it might be good to backpatchlater, after this mechanism has had some more testing in master branch.1 parent5329942 commit1f67078
File tree
10 files changed
+209
-112
lines changed- src
- backend
- access/transam
- libpq
- storage
- file
- smgr
- utils/cache
- include/storage
10 files changed
+209
-112
lines changedLines changed: 12 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
531 | 531 |
| |
532 | 532 |
| |
533 | 533 |
| |
534 |
| - | |
| 534 | + | |
535 | 535 |
| |
536 | 536 |
| |
537 | 537 |
| |
| |||
593 | 593 |
| |
594 | 594 |
| |
595 | 595 |
| |
596 |
| - | |
| 596 | + | |
597 | 597 |
| |
598 | 598 |
| |
599 | 599 |
| |
| |||
614 | 614 |
| |
615 | 615 |
| |
616 | 616 |
| |
617 |
| - | |
| 617 | + | |
618 | 618 |
| |
619 | 619 |
| |
620 | 620 |
| |
| |||
623 | 623 |
| |
624 | 624 |
| |
625 | 625 |
| |
626 |
| - | |
| 626 | + | |
627 | 627 |
| |
628 | 628 |
| |
629 | 629 |
| |
630 |
| - | |
| 630 | + | |
631 | 631 |
| |
632 | 632 |
| |
633 | 633 |
| |
| |||
740 | 740 |
| |
741 | 741 |
| |
742 | 742 |
| |
743 |
| - | |
744 |
| - | |
| 743 | + | |
| 744 | + | |
745 | 745 |
| |
746 | 746 |
| |
747 | 747 |
| |
| |||
773 | 773 |
| |
774 | 774 |
| |
775 | 775 |
| |
776 |
| - | |
| 776 | + | |
777 | 777 |
| |
778 | 778 |
| |
779 | 779 |
| |
| |||
786 | 786 |
| |
787 | 787 |
| |
788 | 788 |
| |
789 |
| - | |
| 789 | + | |
790 | 790 |
| |
791 | 791 |
| |
792 | 792 |
| |
| |||
800 | 800 |
| |
801 | 801 |
| |
802 | 802 |
| |
803 |
| - | |
| 803 | + | |
804 | 804 |
| |
805 | 805 |
| |
806 | 806 |
| |
807 |
| - | |
| 807 | + | |
808 | 808 |
| |
809 | 809 |
| |
810 | 810 |
| |
| |||
1078 | 1078 |
| |
1079 | 1079 |
| |
1080 | 1080 |
| |
1081 |
| - | |
| 1081 | + | |
1082 | 1082 |
| |
1083 | 1083 |
| |
1084 | 1084 |
| |
|
Lines changed: 5 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
244 | 244 |
| |
245 | 245 |
| |
246 | 246 |
| |
247 |
| - | |
248 |
| - | |
| 247 | + | |
| 248 | + | |
249 | 249 |
| |
250 | 250 |
| |
251 | 251 |
| |
| |||
262 | 262 |
| |
263 | 263 |
| |
264 | 264 |
| |
265 |
| - | |
| 265 | + | |
266 | 266 |
| |
267 | 267 |
| |
268 | 268 |
| |
| |||
304 | 304 |
| |
305 | 305 |
| |
306 | 306 |
| |
307 |
| - | |
| 307 | + | |
308 | 308 |
| |
309 | 309 |
| |
310 | 310 |
| |
| |||
345 | 345 |
| |
346 | 346 |
| |
347 | 347 |
| |
348 |
| - | |
| 348 | + | |
349 | 349 |
| |
350 | 350 |
| |
351 | 351 |
| |
|
Lines changed: 24 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
970 | 970 |
| |
971 | 971 |
| |
972 | 972 |
| |
973 |
| - | |
974 |
| - | |
975 |
| - | |
976 |
| - | |
977 |
| - | |
978 | 973 |
| |
979 | 974 |
| |
980 | 975 |
| |
981 |
| - | |
982 |
| - | |
983 |
| - | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
984 | 979 |
| |
985 | 980 |
| |
986 | 981 |
| |
| |||
995 | 990 |
| |
996 | 991 |
| |
997 | 992 |
| |
998 |
| - | |
| 993 | + | |
999 | 994 |
| |
1000 | 995 |
| |
1001 | 996 |
| |
| |||
1012 | 1007 |
| |
1013 | 1008 |
| |
1014 | 1009 |
| |
1015 |
| - | |
| 1010 | + | |
1016 | 1011 |
| |
1017 | 1012 |
| |
1018 | 1013 |
| |
| |||
1021 | 1016 |
| |
1022 | 1017 |
| |
1023 | 1018 |
| |
1024 |
| - | |
| 1019 | + | |
1025 | 1020 |
| |
1026 | 1021 |
| |
1027 | 1022 |
| |
| |||
1061 | 1056 |
| |
1062 | 1057 |
| |
1063 | 1058 |
| |
1064 |
| - | |
| 1059 | + | |
1065 | 1060 |
| |
1066 | 1061 |
| |
1067 | 1062 |
| |
1068 | 1063 |
| |
1069 | 1064 |
| |
1070 |
| - | |
| 1065 | + | |
1071 | 1066 |
| |
1072 | 1067 |
| |
1073 | 1068 |
| |
| |||
1144 | 1139 |
| |
1145 | 1140 |
| |
1146 | 1141 |
| |
1147 |
| - | |
| 1142 | + | |
1148 | 1143 |
| |
1149 | 1144 |
| |
1150 | 1145 |
| |
| |||
1163 | 1158 |
| |
1164 | 1159 |
| |
1165 | 1160 |
| |
1166 |
| - | |
| 1161 | + | |
1167 | 1162 |
| |
1168 | 1163 |
| |
1169 | 1164 |
| |
| |||
1177 | 1172 |
| |
1178 | 1173 |
| |
1179 | 1174 |
| |
1180 |
| - | |
| 1175 | + | |
1181 | 1176 |
| |
1182 | 1177 |
| |
1183 | 1178 |
| |
1184 | 1179 |
| |
1185 | 1180 |
| |
1186 | 1181 |
| |
1187 |
| - | |
| 1182 | + | |
1188 | 1183 |
| |
1189 | 1184 |
| |
1190 | 1185 |
| |
| |||
1195 | 1190 |
| |
1196 | 1191 |
| |
1197 | 1192 |
| |
1198 |
| - | |
| 1193 | + | |
1199 | 1194 |
| |
1200 | 1195 |
| |
1201 | 1196 |
| |
| |||
1205 | 1200 |
| |
1206 | 1201 |
| |
1207 | 1202 |
| |
1208 |
| - | |
| 1203 | + | |
1209 | 1204 |
| |
1210 | 1205 |
| |
1211 | 1206 |
| |
| |||
1469 | 1464 |
| |
1470 | 1465 |
| |
1471 | 1466 |
| |
1472 |
| - | |
1473 |
| - | |
1474 |
| - | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
1475 | 1470 |
| |
1476 | 1471 |
| |
1477 | 1472 |
| |
| |||
1481 | 1476 |
| |
1482 | 1477 |
| |
1483 | 1478 |
| |
1484 |
| - | |
| 1479 | + | |
1485 | 1480 |
| |
1486 | 1481 |
| |
1487 | 1482 |
| |
1488 | 1483 |
| |
1489 | 1484 |
| |
1490 | 1485 |
| |
1491 |
| - | |
| 1486 | + | |
1492 | 1487 |
| |
1493 | 1488 |
| |
1494 | 1489 |
| |
| |||
1500 | 1495 |
| |
1501 | 1496 |
| |
1502 | 1497 |
| |
1503 |
| - | |
| 1498 | + | |
1504 | 1499 |
| |
1505 | 1500 |
| |
1506 | 1501 |
| |
1507 | 1502 |
| |
1508 | 1503 |
| |
1509 |
| - | |
| 1504 | + | |
1510 | 1505 |
| |
1511 | 1506 |
| |
1512 | 1507 |
| |
| |||
1577 | 1572 |
| |
1578 | 1573 |
| |
1579 | 1574 |
| |
1580 |
| - | |
| 1575 | + | |
1581 | 1576 |
| |
1582 | 1577 |
| |
1583 | 1578 |
| |
| |||
1596 | 1591 |
| |
1597 | 1592 |
| |
1598 | 1593 |
| |
1599 |
| - | |
| 1594 | + | |
1600 | 1595 |
| |
1601 | 1596 |
| |
1602 | 1597 |
| |
1603 | 1598 |
| |
1604 | 1599 |
| |
1605 | 1600 |
| |
1606 |
| - | |
| 1601 | + | |
1607 | 1602 |
| |
1608 | 1603 |
| |
1609 | 1604 |
| |
|
0 commit comments
Comments
(0)