Skip to content

Commit 419bd63

Browse files
committed
Fix use-after-free bug when renaming constraints
This is an oversight from recent commit b13fd34. While on it, tweak the previous test with a better name for the renamed primary key. Detected by buildfarm member prion which forces relation cache release with -DRELCACHE_FORCE_RELEASE. Back-patch down to 9.4 as the previous commit.
1 parent d79cd55 commit 419bd63

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,12 +2495,12 @@ rename_constraint_internal(Oid myrelid,
24952495

24962496
if (targetrelation)
24972497
{
2498-
relation_close(targetrelation, NoLock); /* close rel but keep lock */
2499-
25002498
/*
25012499
* Invalidate relcache so as others can see the new constraint name.
25022500
*/
25032501
CacheInvalidateRelcache(targetrelation);
2502+
2503+
relation_close(targetrelation, NoLock); /* close rel but keep lock */
25042504
}
25052505

25062506
return address;

src/test/regress/expected/alter_table.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ CREATE TABLE constraint_rename_cache (a int,
349349
ALTER TABLE constraint_rename_cache
350350
RENAME CONSTRAINT chk_a TO chk_a_new;
351351
ALTER TABLE constraint_rename_cache
352-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
352+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
353353
CREATE TABLE like_constraint_rename_cache
354354
(LIKE constraint_rename_cache INCLUDING ALL);
355355
\d like_constraint_rename_cache

src/test/regress/sql/alter_table.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ CREATE TABLE constraint_rename_cache (a int,
258258
ALTER TABLE constraint_rename_cache
259259
RENAME CONSTRAINT chk_a TO chk_a_new;
260260
ALTER TABLE constraint_rename_cache
261-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
261+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
262262
CREATE TABLE like_constraint_rename_cache
263263
(LIKE constraint_rename_cache INCLUDING ALL);
264264
\d like_constraint_rename_cache

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