@@ -314,7 +314,8 @@ process_syncing_tables_for_sync(XLogRecPtr current_lsn)
314314 */
315315 ReplicationSlotNameForTablesync (MyLogicalRepWorker -> subid ,
316316 MyLogicalRepWorker -> relid ,
317- syncslotname );
317+ syncslotname ,
318+ sizeof (syncslotname ));
318319
319320 /*
320321 * It is important to give an error if we are unable to drop the slot,
@@ -462,7 +463,8 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
462463 */
463464 ReplicationOriginNameForTablesync (MyLogicalRepWorker -> subid ,
464465 rstate -> relid ,
465- originname );
466+ originname ,
467+ sizeof (originname ));
466468 replorigin_drop_by_name (originname , true, false);
467469
468470 /*
@@ -871,27 +873,20 @@ copy_table(Relation rel)
871873 * pg_%u_sync_%u_UINT64_FORMAT (3 + 10 + 6 + 10 + 20 + '\0'), the maximum
872874 * length of slot_name will be 50.
873875 *
874- * The returned slot name is either:
875- * - stored in the supplied buffer (syncslotname), or
876- * - palloc'ed in current memory context (if syncslotname = NULL).
876+ * The returned slot name is stored in the supplied buffer (syncslotname) with
877+ * the given size.
877878 *
878879 * Note: We don't use the subscription slot name as part of tablesync slot name
879880 * because we are responsible for cleaning up these slots and it could become
880881 * impossible to recalculate what name to cleanup if the subscription slot name
881882 * had changed.
882883 */
883- char *
884+ void
884885ReplicationSlotNameForTablesync (Oid suboid , Oid relid ,
885- char syncslotname [ NAMEDATALEN ] )
886+ char * syncslotname , int szslot )
886887{
887- if (syncslotname )
888- sprintf (syncslotname , "pg_%u_sync_%u_" UINT64_FORMAT , suboid , relid ,
889- GetSystemIdentifier ());
890- else
891- syncslotname = psprintf ("pg_%u_sync_%u_" UINT64_FORMAT , suboid , relid ,
892- GetSystemIdentifier ());
893-
894- return syncslotname ;
888+ snprintf (syncslotname , szslot , "pg_%u_sync_%u_" UINT64_FORMAT , suboid ,
889+ relid , GetSystemIdentifier ());
895890}
896891
897892/*
@@ -901,9 +896,9 @@ ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
901896 */
902897void
903898ReplicationOriginNameForTablesync (Oid suboid , Oid relid ,
904- char originname [ NAMEDATALEN ] )
899+ char * originname , int szorgname )
905900{
906- snprintf (originname , NAMEDATALEN , "pg_%u_%u" , suboid , relid );
901+ snprintf (originname , szorgname , "pg_%u_%u" , suboid , relid );
907902}
908903
909904/*
@@ -951,9 +946,11 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
951946 }
952947
953948 /* Calculate the name of the tablesync slot. */
954- slotname = ReplicationSlotNameForTablesync (MySubscription -> oid ,
955- MyLogicalRepWorker -> relid ,
956- NULL /* use palloc */ );
949+ slotname = (char * ) palloc (NAMEDATALEN );
950+ ReplicationSlotNameForTablesync (MySubscription -> oid ,
951+ MyLogicalRepWorker -> relid ,
952+ slotname ,
953+ NAMEDATALEN );
957954
958955 /*
959956 * Here we use the slot name instead of the subscription name as the
@@ -972,7 +969,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
972969 /* Assign the origin tracking record name. */
973970 ReplicationOriginNameForTablesync (MySubscription -> oid ,
974971 MyLogicalRepWorker -> relid ,
975- originname );
972+ originname ,
973+ sizeof (originname ));
976974
977975 if (MyLogicalRepWorker -> relstate == SUBREL_STATE_DATASYNC )
978976 {
0 commit comments