forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork0
Commit232d8ca
committed
Fix memory leakage in postgres_fdw's DirectModify code path.
postgres_fdw tries to use PG_TRY blocks to ensure that it willeventually free the PGresult created by the remote modify command.However, it's fundamentally impossible for this scheme to workreliably when there's RETURNING data, because the query could failin between invocations of postgres_fdw's DirectModify methods.There is at least one instance of exactly this situation in theregression tests, and the ensuing session-lifespan leak is visibleunder Valgrind.We can improve matters by using a memory context reset callbackattached to the ExecutorState context. That ensures that thePGresult will be freed when the ExecutorState context is torndown, even if control never reaches postgresEndDirectModify.I have little faith that there aren't other potential PGresultleakages in the backend modules that use libpq. So I think it'dbe a good idea to apply this concept universally by creatinginfrastructure that attaches a reset callback to every PGresultgenerated in the backend. However, that seems too invasive forv18 at this point, let alone the back branches. So for themoment, apply this narrow fix that just makes DirectModify safe.I have a patch in the queue for the more general idea, but itwill have to wait for v19.Author: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>Discussion:https://postgr.es/m/2976982.1748049023@sss.pgh.pa.usBackpatch-through: 131 parentd98cefe commit232d8ca
1 file changed
+35
-27
lines changedLines changed: 35 additions & 27 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
240 | 240 |
| |
241 | 241 |
| |
242 | 242 |
| |
| 243 | + | |
243 | 244 |
| |
244 | 245 |
| |
245 | 246 |
| |
| |||
2670 | 2671 |
| |
2671 | 2672 |
| |
2672 | 2673 |
| |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
2673 | 2685 |
| |
2674 | 2686 |
| |
2675 | 2687 |
| |
| |||
2817 | 2829 |
| |
2818 | 2830 |
| |
2819 | 2831 |
| |
2820 |
| - | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
2821 | 2839 |
| |
2822 | 2840 |
| |
2823 | 2841 |
| |
| |||
4591 | 4609 |
| |
4592 | 4610 |
| |
4593 | 4611 |
| |
4594 |
| - | |
4595 |
| - | |
| 4612 | + | |
| 4613 | + | |
| 4614 | + | |
4596 | 4615 |
| |
| 4616 | + | |
4597 | 4617 |
| |
| 4618 | + | |
| 4619 | + | |
4598 | 4620 |
| |
4599 | 4621 |
| |
4600 |
| - | |
| 4622 | + | |
4601 | 4623 |
| |
4602 | 4624 |
| |
4603 | 4625 |
| |
| |||
4641 | 4663 |
| |
4642 | 4664 |
| |
4643 | 4665 |
| |
4644 |
| - | |
4645 |
| - | |
4646 |
| - | |
4647 |
| - | |
4648 |
| - | |
4649 |
| - | |
4650 |
| - | |
4651 |
| - | |
4652 |
| - | |
4653 |
| - | |
4654 |
| - | |
4655 |
| - | |
4656 |
| - | |
4657 |
| - | |
4658 |
| - | |
4659 |
| - | |
4660 |
| - | |
4661 |
| - | |
4662 |
| - | |
4663 |
| - | |
4664 |
| - | |
4665 |
| - | |
4666 |
| - | |
| 4666 | + | |
4667 | 4667 |
| |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
| 4671 | + | |
| 4672 | + | |
| 4673 | + | |
| 4674 | + | |
| 4675 | + | |
4668 | 4676 |
| |
4669 | 4677 |
| |
4670 | 4678 |
| |
|
0 commit comments
Comments
(0)