Skip to content

Commit 16a906f

Browse files
committed
Make DISCARD SEQUENCES also discard the last used sequence.
Otherwise, we access already-freed memory. Oops. Report by Michael Paquier. Fix by me.
1 parent 689746c commit 16a906f

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/backend/commands/sequence.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,4 +1617,6 @@ ResetSequenceCaches(void)
16171617
free(seqtab);
16181618
seqtab = next;
16191619
}
1620+
1621+
last_used_seq = NULL;
16201622
}

src/test/regress/expected/sequence.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ SELECT lastval();
344344
99
345345
(1 row)
346346

347+
DISCARD SEQUENCES;
348+
SELECT lastval();
349+
ERROR: lastval is not yet defined in this session
347350
CREATE SEQUENCE seq2;
348351
SELECT nextval('seq2');
349352
nextval

src/test/regress/sql/sequence.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ SELECT nextval('seq');
154154
SELECT lastval();
155155
SELECT setval('seq', 99);
156156
SELECT lastval();
157+
DISCARD SEQUENCES;
158+
SELECT lastval();
157159

158160
CREATE SEQUENCE seq2;
159161
SELECT nextval('seq2');

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