forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita3bed62
committed
Fix low-probability leaks of PGresult objects in the backend.
We had three occurrences of essentially the same coding patternwherein we tried to retrieve a query result from a libpq connectionwithout blocking. In the case where PQconsumeInput failed (typicallyindicating a lost connection), all three loops simply gave up andreturned, forgetting to clear any previously-collected PGresultobject. Since those are malloc'd not palloc'd, the oversight resultsin a process-lifespan memory leak.One instance, in libpqwalreceiver, is of little significance becausethe walreceiver process would just quit anyway if its connection fails.But we might as well fix it.The other two instances, in postgres_fdw, are somewhat more worrisomebecause at least in principle the scenario could be repeated, allowingthe amount of memory leaked to build up to something worth worryingabout. Moreover, in these cases the loops contain CHECK_FOR_INTERRUPTScalls, as well as other calls that could potentially elog(ERROR),providing another way to exit without having cleared the PGresult.Here we need to add PG_TRY logic similar to what exists in quite afew other places in postgres_fdw.Coverity noted the libpqwalreceiver bug; I found the other two casesby checking all calls of PQconsumeInput.Back-patch to all supported versions as appropriate (9.2 lackspostgres_fdw, so this is really quite unexciting for that branch).Discussion:https://postgr.es/m/22620.1497486981@sss.pgh.pa.us1 parent07fb943 commita3bed62
File tree
2 files changed
+101
-65
lines changed- contrib/postgres_fdw
- src/backend/replication/libpqwalreceiver
2 files changed
+101
-65
lines changedLines changed: 92 additions & 62 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
485 | 485 |
| |
486 | 486 |
| |
487 | 487 |
| |
488 |
| - | |
| 488 | + | |
489 | 489 |
| |
490 | 490 |
| |
491 | 491 |
| |
492 | 492 |
| |
493 | 493 |
| |
494 | 494 |
| |
495 | 495 |
| |
496 |
| - | |
| 496 | + | |
497 | 497 |
| |
498 |
| - | |
| 498 | + | |
| 499 | + | |
499 | 500 |
| |
500 |
| - | |
501 |
| - | |
502 |
| - | |
| 501 | + | |
503 | 502 |
| |
504 |
| - | |
| 503 | + | |
505 | 504 |
| |
506 |
| - | |
507 |
| - | |
508 |
| - | |
509 |
| - | |
510 |
| - | |
511 |
| - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
512 | 508 |
| |
513 |
| - | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
514 | 515 |
| |
515 |
| - | |
516 |
| - | |
517 |
| - | |
518 |
| - | |
519 |
| - | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
520 | 524 |
| |
521 |
| - | |
522 | 525 |
| |
523 |
| - | |
524 |
| - | |
525 |
| - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
526 | 529 |
| |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
527 | 536 |
| |
528 |
| - | |
| 537 | + | |
529 | 538 |
| |
| 539 | + | |
530 | 540 |
| |
531 | 541 |
| |
532 | 542 |
| |
| |||
1006 | 1016 |
| |
1007 | 1017 |
| |
1008 | 1018 |
| |
| 1019 | + | |
1009 | 1020 |
| |
1010 | 1021 |
| |
1011 | 1022 |
| |
| |||
1028 | 1039 |
| |
1029 | 1040 |
| |
1030 | 1041 |
| |
1031 |
| - | |
| 1042 | + | |
| 1043 | + | |
1032 | 1044 |
| |
1033 |
| - | |
| 1045 | + | |
| 1046 | + | |
1034 | 1047 |
| |
1035 |
| - | |
1036 |
| - | |
1037 |
| - | |
| 1048 | + | |
1038 | 1049 |
| |
1039 |
| - | |
1040 |
| - | |
1041 |
| - | |
1042 |
| - | |
1043 |
| - | |
1044 |
| - | |
1045 |
| - | |
1046 |
| - | |
1047 |
| - | |
1048 |
| - | |
1049 |
| - | |
1050 |
| - | |
1051 |
| - | |
1052 |
| - | |
1053 |
| - | |
1054 |
| - | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
1055 | 1073 |
| |
1056 |
| - | |
1057 |
| - | |
1058 |
| - | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
1059 | 1077 |
| |
1060 |
| - | |
| 1078 | + | |
1061 | 1079 |
| |
1062 |
| - | |
1063 |
| - | |
1064 |
| - | |
1065 |
| - | |
| 1080 | + | |
| 1081 | + | |
1066 | 1082 |
| |
1067 |
| - | |
1068 |
| - | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1069 | 1089 |
| |
1070 | 1090 |
| |
1071 |
| - | |
1072 | 1091 |
| |
1073 |
| - | |
1074 |
| - | |
1075 |
| - | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
1076 | 1095 |
| |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
1077 | 1103 |
| |
1078 |
| - | |
| 1104 | + | |
1079 | 1105 |
| |
| 1106 | + | |
1080 | 1107 |
| |
1081 |
| - | |
1082 |
| - | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
1083 | 1113 |
|
Lines changed: 9 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
591 | 591 |
| |
592 | 592 |
| |
593 | 593 |
| |
| 594 | + | |
| 595 | + | |
594 | 596 |
| |
595 |
| - | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
596 | 602 |
| |
597 | 603 |
| |
598 | 604 |
| |
599 |
| - | |
600 |
| - | |
| 605 | + | |
| 606 | + | |
601 | 607 |
| |
602 | 608 |
| |
603 | 609 |
| |
|
0 commit comments
Comments
(0)