Commit 608cf2b
committed
Fix ancient memory leak in contrib/auto_explain.
The ExecutorEnd hook is invoked in a context that could be quite
long-lived, not the executor's own per-query context as I think
we were sort of assuming. Thus, any cruft generated while producing
the EXPLAIN output could accumulate over multiple queries. This can
result in spectacular leakage if log_nested_statements is on, and
even without that I'm surprised nobody complained before.
To fix, just switch into the executor's context so that anything we
allocate will be released when standard_ExecutorEnd frees the executor
state. We might as well nuke the code's retail pfree of the explain
output string, too; that's laughably inadequate to the need.
Japin Li, per report from Jeff Janes. This bug is old, so
back-patch to all supported branches.
Discussion: https://postgr.es/m/CAMkU=1wCVtbeRn0s9gt12KwQ7PLXovbpM8eg25SYocKW3BT4hg@mail.gmail.com1 parent d683d65 commit 608cf2bCopy full SHA for 608cf2b
File tree
Expand file treeCollapse file tree
1 file changed
+9
-2
lines changedOpen diff view settings
Filter options
- contrib/auto_explain
Expand file treeCollapse file tree
1 file changed
+9
-2
lines changedOpen diff view settings
Collapse file
contrib/auto_explain/auto_explain.c
Copy file name to clipboardExpand all lines: contrib/auto_explain/auto_explain.c+9-2Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
320 | 320 | |
321 | 321 | |
322 | 322 | |
| 323 | + |
323 | 324 | |
324 | 325 | |
| 326 | + |
| 327 | + |
| 328 | + |
| 329 | + |
| 330 | + |
| 331 | + |
325 | 332 | |
326 | 333 | |
327 | 334 | |
| ||
369 | 376 | |
370 | 377 | |
371 | 378 | |
372 | | - |
373 | | - |
374 | 379 | |
| 380 | + |
| 381 | + |
375 | 382 | |
376 | 383 | |
377 | 384 | |
|
0 commit comments