forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitba230ce
committed
Fix memory leak in pgoutput with publication list cache
The pgoutput module caches publication names in a list and frees it uponinvalidation. However, the code forgot to free the actual publicationnames within the list elements, as publication names are pstrdup()'d inGetPublication(). This would cause memory to leak inCacheMemoryContext, bloating it over time as this context is notcleaned.This is a problem for WAL senders running for a long time, as anaccumulation of invalidation requests would bloat its cache memoryusage. A second case, where this leak is easier to see, involves abackend calling SQL functions like pg_logical_slot_{get,peek}_changes()which create a new decoding context with each execution. Morepublications create more bloat.To address this, this commit adds a new memory context within thelogical decoding context and resets it each time the publication namescache is invalidated, based on a suggestion from Amit Kapila. Thisensures that the lifespan of the publication names aligns with that ofthe logical decoding context.Contrary to the HEAD-only commitf0c569d that has changedPGOutputData to track this new child memory context, the context istracked with a static variable whose state is reset with a MemoryContextreset callback attached to PGOutputData->context, so as ABIcompatibility is preserved in stable branches. This approach is basedon an suggestion from Amit Kapila.Analyzed-by: Michael Paquier, Jeff DavisAuthor: Masahiko SawadaReviewed-by: Amit Kapila, Michael Paquier, Euler Taveira, Hou ZhijieDiscussion:https://postgr.es/m/Z0khf9EVMVLOc_YY@paquier.xyzBackpatch-through: 131 parent9c1afd3 commitba230ce
1 file changed
+36
-5
lines changedLines changed: 36 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
52 | 59 |
| |
53 | 60 |
| |
54 | 61 |
| |
| |||
174 | 181 |
| |
175 | 182 |
| |
176 | 183 |
| |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
177 | 193 |
| |
178 | 194 |
| |
179 | 195 |
| |
| |||
183 | 199 |
| |
184 | 200 |
| |
185 | 201 |
| |
| 202 | + | |
186 | 203 |
| |
187 | 204 |
| |
188 | 205 |
| |
189 | 206 |
| |
190 | 207 |
| |
191 | 208 |
| |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
192 | 218 |
| |
193 | 219 |
| |
194 | 220 |
| |
| |||
587 | 613 |
| |
588 | 614 |
| |
589 | 615 |
| |
590 |
| - | |
591 |
| - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
592 | 619 |
| |
593 | 620 |
| |
594 | 621 |
| |
| |||
598 | 625 |
| |
599 | 626 |
| |
600 | 627 |
| |
| 628 | + | |
| 629 | + | |
| 630 | + | |
601 | 631 |
| |
602 | 632 |
| |
603 | 633 |
| |
| |||
731 | 761 |
| |
732 | 762 |
| |
733 | 763 |
| |
734 |
| - | |
735 |
| - | |
736 |
| - | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
737 | 768 |
| |
738 | 769 |
| |
739 | 770 |
| |
|
0 commit comments
Comments
(0)