v2-0001-use-alloc-macros-in-logical-replication-code.patch
application/octet-stream
Filename: v2-0001-use-alloc-macros-in-logical-replication-code.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch v2-0001
Subject: use alloc macros in logical replication code
| File | + | − |
|---|---|---|
| src/backend/replication/logical/proto.c | 1 | 1 |
| src/backend/replication/logical/reorderbuffer.c | 4 | 4 |
| src/backend/replication/logical/snapbuild.c | 4 | 3 |
| src/backend/replication/logical/tablesync.c | 2 | 2 |
| src/backend/replication/logical/worker.c | 7 | 7 |
From b345e4d7e7d1f36eb5ad51d904c2005d2687a81d Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Wed, 4 Feb 2026 16:32:31 +1100
Subject: [PATCH v2] use alloc macros in logical replication code
---
src/backend/replication/logical/proto.c | 2 +-
src/backend/replication/logical/reorderbuffer.c | 8 ++++----
src/backend/replication/logical/snapbuild.c | 7 ++++---
src/backend/replication/logical/tablesync.c | 4 ++--
src/backend/replication/logical/worker.c | 14 +++++++-------
5 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/src/backend/replication/logical/proto.c b/src/backend/replication/logical/proto.c
index 3950dd0cf46..86ad97cd937 100644
--- a/src/backend/replication/logical/proto.c
+++ b/src/backend/replication/logical/proto.c
@@ -870,7 +870,7 @@ logicalrep_read_tuple(StringInfo in, LogicalRepTupleData *tuple)
natts = pq_getmsgint(in, 2);
/* Allocate space for per-column values; zero out unused StringInfoDatas */
- tuple->colvalues = (StringInfoData *) palloc0(natts * sizeof(StringInfoData));
+ tuple->colvalues = palloc0_array(StringInfoData, natts);
tuple->colstatus = palloc_array(char, natts);
tuple->ncols = natts;
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 2d2a6d5e9e7..922bb504c1e 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -2490,7 +2490,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn,
int nrelations = 0;
Relation *relations;
- relations = palloc0(nrelids * sizeof(Relation));
+ relations = palloc0_array(Relation, nrelids);
for (i = 0; i < nrelids; i++)
{
Oid relid = change->data.truncate.relids[i];
@@ -3516,9 +3516,9 @@ ReorderBufferAccumulateInvalidations(SharedInvalidationMessage **invals_out,
else
{
/* Enlarge the array of inval messages */
- *invals_out = (SharedInvalidationMessage *)
- repalloc(*invals_out, sizeof(SharedInvalidationMessage) *
- (*ninvals_out + nmsgs_new));
+ *invals_out =
+ repalloc_array(*invals_out, SharedInvalidationMessage,
+ (*ninvals_out + nmsgs_new));
memcpy(*invals_out + *ninvals_out, msgs_new,
nmsgs_new * sizeof(SharedInvalidationMessage));
*ninvals_out += nmsgs_new;
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 7f79621b57e..c94a548d6a3 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -209,7 +209,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
builder->committed.xcnt = 0;
builder->committed.xcnt_space = 128; /* arbitrary number */
builder->committed.xip =
- palloc0(builder->committed.xcnt_space * sizeof(TransactionId));
+ palloc0_array(TransactionId, builder->committed.xcnt_space);
builder->committed.includes_all_transactions = true;
builder->catchange.xcnt = 0;
@@ -836,8 +836,9 @@ SnapBuildAddCommittedTxn(SnapBuild *builder, TransactionId xid)
elog(DEBUG1, "increasing space for committed transactions to %u",
(uint32) builder->committed.xcnt_space);
- builder->committed.xip = repalloc(builder->committed.xip,
- builder->committed.xcnt_space * sizeof(TransactionId));
+ builder->committed.xip = repalloc_array(builder->committed.xip,
+ TransactionId,
+ builder->committed.xcnt_space);
}
/*
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 19a3c21a863..02ba03b62a9 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -899,8 +899,8 @@ fetch_remote_table_info(char *nspname, char *relname, LogicalRepRelation *lrel,
nspname, relname, res->err)));
/* We don't know the number of rows coming, so allocate enough space. */
- lrel->attnames = palloc0(MaxTupleAttributeNumber * sizeof(char *));
- lrel->atttyps = palloc0(MaxTupleAttributeNumber * sizeof(Oid));
+ lrel->attnames = palloc0_array(char *, MaxTupleAttributeNumber);
+ lrel->atttyps = palloc0_array(Oid, MaxTupleAttributeNumber);
lrel->attkeys = NULL;
/*
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 32725c48623..79c2d3ed863 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -974,8 +974,8 @@ slot_fill_defaults(LogicalRepRelMapEntry *rel, EState *estate,
if (num_phys_attrs == rel->remoterel.natts)
return;
- defmap = (int *) palloc(num_phys_attrs * sizeof(int));
- defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
+ defmap = palloc_array(int, num_phys_attrs);
+ defexprs = palloc_array(ExprState *, num_phys_attrs);
Assert(rel->attrmap->maplen == num_phys_attrs);
for (attnum = 0; attnum < num_phys_attrs; attnum++)
@@ -5264,8 +5264,8 @@ subxact_info_read(Oid subid, TransactionId xid)
* to the subxact file and reset the logical streaming context.
*/
oldctx = MemoryContextSwitchTo(LogicalStreamingContext);
- subxact_data.subxacts = palloc(subxact_data.nsubxacts_max *
- sizeof(SubXactInfo));
+ subxact_data.subxacts = palloc_array(SubXactInfo,
+ subxact_data.nsubxacts_max);
MemoryContextSwitchTo(oldctx);
if (len > 0)
@@ -5331,14 +5331,14 @@ subxact_info_add(TransactionId xid)
* subxact_info_read.
*/
oldctx = MemoryContextSwitchTo(LogicalStreamingContext);
- subxacts = palloc(subxact_data.nsubxacts_max * sizeof(SubXactInfo));
+ subxacts = palloc_array(SubXactInfo, subxact_data.nsubxacts_max);
MemoryContextSwitchTo(oldctx);
}
else if (subxact_data.nsubxacts == subxact_data.nsubxacts_max)
{
subxact_data.nsubxacts_max *= 2;
- subxacts = repalloc(subxacts,
- subxact_data.nsubxacts_max * sizeof(SubXactInfo));
+ subxacts = repalloc_array(subxacts, SubXactInfo,
+ subxact_data.nsubxacts_max);
}
subxacts[subxact_data.nsubxacts].xid = xid;
--
2.47.3