forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork0
Commitbe86ca1
committed
Fix memory leakage when function compilation fails.
In pl_comp.c, initially create the plpgsql function's cache contextunder the assumed-short-lived caller's context, and reparent it underCacheMemoryContext only upon success. This avoids a process-lifespanleak of 8kB or more if the function contains syntax errors. (Thisleakage has existed for a long time without many complaints, but aswe move towards a possibly multi-threaded future, getting rid ofprocess-lifespan leaks grows more important.)In funccache.c, arrange to reclaim the CachedFunction struct in casethe language-specific compile callback function throws an error;previously, that resulted in an independent process-lifespan leak.This is arguably a new bug in v18, since the leakage now occurredfor SQL-language functions as well as plpgsql.Also, don't fill fn_xmin/fn_tid/dcallback until after successfulcompletion of the compile callback. This avoids a scenario where apartially-built function cache might appear already valid upon laterinspection, and another scenario where dcallback might fail upon beingpresented with an incomplete cache entry. We would have to reach sucha faulty cache entry via a pre-existing fn_extra pointer, so I'm notsure these scenarios correspond to any live bug. (The predecessorcode in pl_comp.c never took any care about this, and we've heard nocomplaints about that.) Still, it's better to be careful.Given the lack of field complaints, I'm not very excited aboutback-patching any of this; but it seems still in-scope for v18.Discussion:https://postgr.es/m/999171.1748300004@sss.pgh.pa.us1 parentc861092 commitbe86ca1
2 files changed
+41
-9
lines changedLines changed: 30 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
491 | 491 |
| |
492 | 492 |
| |
493 | 493 |
| |
| 494 | + | |
494 | 495 |
| |
495 | 496 |
| |
496 | 497 |
| |
| |||
570 | 571 |
| |
571 | 572 |
| |
572 | 573 |
| |
573 |
| - | |
| 574 | + | |
| 575 | + | |
574 | 576 |
| |
575 | 577 |
| |
576 | 578 |
| |
577 | 579 |
| |
578 | 580 |
| |
579 | 581 |
| |
| 582 | + | |
580 | 583 |
| |
581 | 584 |
| |
582 | 585 |
| |
| |||
585 | 588 |
| |
586 | 589 |
| |
587 | 590 |
| |
588 |
| - | |
589 |
| - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
590 | 597 |
| |
591 |
| - | |
592 |
| - | |
593 |
| - | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
594 | 612 |
| |
595 | 613 |
| |
596 |
| - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
597 | 617 |
| |
598 |
| - | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
599 | 621 |
| |
600 | 622 |
| |
601 | 623 |
| |
|
Lines changed: 11 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
226 | 226 |
| |
227 | 227 |
| |
228 | 228 |
| |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
229 | 234 |
| |
230 |
| - | |
| 235 | + | |
231 | 236 |
| |
232 | 237 |
| |
233 | 238 |
| |
| |||
703 | 708 |
| |
704 | 709 |
| |
705 | 710 |
| |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
706 | 716 |
| |
707 | 717 |
| |
708 | 718 |
| |
|
0 commit comments
Comments
(0)