From e52b5664f4ab5564ac0d2e2c9b238348f4a1e038 Mon Sep 17 00:00:00 2001 From: "houzj.fnst" Date: Mon, 13 Jun 2022 14:42:55 +0800 Subject: [PATCH v6 4/4] fix memory leak about attrmap Use free_attrmap instead of pfree to release AttrMap structure. Check the attrmap again when opening the relation and clean up the invalid AttrMap before rebuilding it. --- src/backend/replication/logical/relation.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index 1a9ed664dd..06be13504a 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -144,7 +144,10 @@ logicalrep_relmap_free_entry(LogicalRepRelMapEntry *entry) bms_free(remoterel->attkeys); if (entry->attrmap) - pfree(entry->attrmap); + { + free_attrmap(entry->attrmap); + entry->attrmap = NULL; + } } /* @@ -378,6 +381,13 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode) int i; Bitmapset *missingatts; + /* cleanup the invalid attrmap */ + if (entry->attrmap) + { + free_attrmap(entry->attrmap); + entry->attrmap = NULL; + } + /* Try to find and lock the relation by name. */ relid = RangeVarGetRelid(makeRangeVar(remoterel->nspname, remoterel->relname, -1), @@ -610,6 +620,13 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root, part_entry->partoid = partOid; } + /* cleanup the invalid attrmap */ + if (entry->attrmap) + { + free_attrmap(entry->attrmap); + entry->attrmap = NULL; + } + if (!entry->remoterel.remoteid) { int i; -- 2.24.0.windows.2