Skip to content

Commit 67915fb

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 b13fd34 commit 67915fb

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

30213021
if (targetrelation)
30223022
{
3023-
relation_close(targetrelation, NoLock); /* close rel but keep lock */
3024-
30253023
/*
30263024
* Invalidate relcache so as others can see the new constraint name.
30273025
*/
30283026
CacheInvalidateRelcache(targetrelation);
3027+
3028+
relation_close(targetrelation, NoLock); /* close rel but keep lock */
30293029
}
30303030

30313031
return address;

src/test/regress/expected/alter_table.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ CREATE TABLE constraint_rename_cache (a int,
400400
ALTER TABLE constraint_rename_cache
401401
RENAME CONSTRAINT chk_a TO chk_a_new;
402402
ALTER TABLE constraint_rename_cache
403-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
403+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
404404
CREATE TABLE like_constraint_rename_cache
405405
(LIKE constraint_rename_cache INCLUDING ALL);
406406
\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
@@ -296,7 +296,7 @@ CREATE TABLE constraint_rename_cache (a int,
296296
ALTER TABLE constraint_rename_cache
297297
RENAME CONSTRAINT chk_a TO chk_a_new;
298298
ALTER TABLE constraint_rename_cache
299-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
299+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
300300
CREATE TABLE like_constraint_rename_cache
301301
(LIKE constraint_rename_cache INCLUDING ALL);
302302
\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