Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e83e098

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 25b8094 commit e83e098

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
@@ -3027,12 +3027,12 @@ rename_constraint_internal(Oid myrelid,
30273027

30283028
if (targetrelation)
30293029
{
3030-
relation_close(targetrelation, NoLock); /* close rel but keep lock */
3031-
30323030
/*
30333031
* Invalidate relcache so as others can see the new constraint name.
30343032
*/
30353033
CacheInvalidateRelcache(targetrelation);
3034+
3035+
relation_close(targetrelation, NoLock); /* close rel but keep lock */
30363036
}
30373037

30383038
return address;

src/test/regress/expected/alter_table.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ CREATE TABLE constraint_rename_cache (a int,
406406
ALTER TABLE constraint_rename_cache
407407
RENAME CONSTRAINT chk_a TO chk_a_new;
408408
ALTER TABLE constraint_rename_cache
409-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
409+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
410410
CREATE TABLE like_constraint_rename_cache
411411
(LIKE constraint_rename_cache INCLUDING ALL);
412412
\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
@@ -308,7 +308,7 @@ CREATE TABLE constraint_rename_cache (a int,
308308
ALTER TABLE constraint_rename_cache
309309
RENAME CONSTRAINT chk_a TO chk_a_new;
310310
ALTER TABLE constraint_rename_cache
311-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
311+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
312312
CREATE TABLE like_constraint_rename_cache
313313
(LIKE constraint_rename_cache INCLUDING ALL);
314314
\d like_constraint_rename_cache

0 commit comments

Comments
 (0)