postgres.git / summary / log / commit / refs

commit    8df3d355db0fcb56535644c5ea2f4ae6f7dfacdf
Author:   Amit Kapila <akapila@postgresql.org>
Date:     Wed Sep 03 06:17:08 2025 +0000
First released in: 18.0

    Fix use-after-free issue in slot synchronization.
    
    Author: Shlok Kyal <shlok.kyal.oss@gmail.com>
    Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
    Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
    Backpatch-through: 18, where it was introduced
    Discussion: https://postgr.es/m/CANhcyEXMrcEdzj-RNGJam0nJHM4y+ttdWsgUCFmXciM7BNKc7A@mail.gmail.com


src/backend/replication/logical/slotsync.c | 3 ++- src/backend/replication/slotfuncs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c index 0be941c643c..e534ccc449a 100644 --- a/src/backend/replication/logical/slotsync.c +++ b/src/backend/replication/logical/slotsync.c @@ -1477,7 +1477,6 @@ ReplSlotSyncWorkerMain(const void *startup_data, size_t startup_data_len) */ wrconn = walrcv_connect(PrimaryConnInfo, false, false, false, app_name.data, &err); - pfree(app_name.data); if (!wrconn) ereport(ERROR, @@ -1485,6 +1484,8 @@ ReplSlotSyncWorkerMain(const void *startup_data, size_t startup_data_len) errmsg("synchronization worker \"%s\" could not connect to the primary server: %s", app_name.data, err)); + pfree(app_name.data); + /* * Register the disconnection callback. * diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index 36cc2ed4e44..f5b1793c1c5 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -921,7 +921,6 @@ pg_sync_replication_slots(PG_FUNCTION_ARGS) /* Connect to the primary server. */ wrconn = walrcv_connect(PrimaryConnInfo, false, false, false, app_name.data, &err); - pfree(app_name.data); if (!wrconn) ereport(ERROR, @@ -929,6 +928,8 @@ pg_sync_replication_slots(PG_FUNCTION_ARGS) errmsg("synchronization worker \"%s\" could not connect to the primary server: %s", app_name.data, err)); + pfree(app_name.data); + SyncReplicationSlots(wrconn); walrcv_disconnect(wrconn); [parent: ae53537e218a]