Skip to content

Commit 98640f9

Browse files
committed
Fix memory leak in Incremental Sort rescans
The Incremental Sort had a couple issues, resulting in leaking memory during rescans, possibly triggering OOM. The code had a couple of related flaws: 1. During rescans, the sort states were reset but then also set to NULL (despite the comment saying otherwise). ExecIncrementalSort then sees NULL and initializes a new sort state, leaking the memory used by the old one. 2. Initializing the sort state also automatically rebuilt the info about presorted keys, leaking the already initialized info. presorted_keys was also unnecessarily reset to NULL. Patch by James Coleman, based on patches by Laurenz Albe and Tom Lane. Backpatch to 13, where Incremental Sort was introduced. Author: James Coleman, Laurenz Albe, Tom Lane Reported-by: Laurenz Albe, Zu-Ming Jiang Backpatch-through: 13 Discussion: https://postgr.es/m/b2bd02dff61af15e3526293e2771f874cf2a3be7.camel%40cybertec.at Discussion: https://postgr.es/m/db03c582-086d-e7cd-d4a1-3bc722f81765%40inf.ethz.ch
1 parent 0457109 commit 98640f9

File tree

1 file changed

+0
-7
lines changed

1 file changed

+0
-7
lines changed

src/backend/executor/nodeIncrementalSort.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ ExecReScanIncrementalSort(IncrementalSortState *node)
11401140
node->outerNodeDone = false;
11411141
node->n_fullsort_remaining = 0;
11421142
node->bound_Done = 0;
1143-
node->presorted_keys = NULL;
11441143

11451144
node->execution_status = INCSORT_LOADFULLSORT;
11461145

@@ -1153,15 +1152,9 @@ ExecReScanIncrementalSort(IncrementalSortState *node)
11531152
* cause a leak.
11541153
*/
11551154
if (node->fullsort_state != NULL)
1156-
{
11571155
tuplesort_reset(node->fullsort_state);
1158-
node->fullsort_state = NULL;
1159-
}
11601156
if (node->prefixsort_state != NULL)
1161-
{
11621157
tuplesort_reset(node->prefixsort_state);
1163-
node->prefixsort_state = NULL;
1164-
}
11651158

11661159
/*
11671160
* If chgParam of subnode is not null, then the plan will be re-scanned by

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy