Skip to content

Commit c6a4ace

Browse files
committed
Fix broken logic in logical_heap_rewrite_flush_mappings().
It's blatantly obvious that commit 4d0d607 wasn't tested. The leak's real enough, though.
1 parent cee850c commit c6a4ace

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/backend/access/heap/rewriteheap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,7 @@ logical_heap_rewrite_flush_mappings(RewriteState state)
897897

898898
/* write all mappings consecutively */
899899
len = src->num_mappings * sizeof(LogicalRewriteMappingData);
900-
waldata = palloc(len);
901-
waldata_start = waldata;
900+
waldata_start = waldata = palloc(len);
902901

903902
/*
904903
* collect data we need to write out, but don't modify ondisk data yet
@@ -921,6 +920,9 @@ logical_heap_rewrite_flush_mappings(RewriteState state)
921920
src->num_mappings--;
922921
}
923922

923+
Assert(src->num_mappings == 0);
924+
Assert(waldata == waldata_start + len);
925+
924926
/*
925927
* Note that we deviate from the usual WAL coding practices here,
926928
* check the above "Logical rewrite support" comment for reasoning.
@@ -933,8 +935,6 @@ logical_heap_rewrite_flush_mappings(RewriteState state)
933935
written, len)));
934936
src->off += len;
935937

936-
Assert(src->num_mappings == 0);
937-
938938
rdata[1].data = waldata_start;
939939
rdata[1].len = len;
940940
rdata[1].buffer = InvalidBuffer;
@@ -943,6 +943,7 @@ logical_heap_rewrite_flush_mappings(RewriteState state)
943943
/* write xlog record */
944944
XLogInsert(RM_HEAP2_ID, XLOG_HEAP2_REWRITE, rdata);
945945

946+
pfree(waldata_start);
946947
}
947948
Assert(state->rs_num_rewrite_mappings == 0);
948949
}

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