From 9989d37d1c8dff12f20a1de8e1f470093136c893 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 3 Dec 2019 15:06:04 +0900 Subject: Remove XLogFileNameP() from the tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit XLogFileNameP() is a wrapper routine able to build a palloc'd string for a WAL segment name, which is used for error string generation. There were several code paths where it gets called in a critical section, where memory allocation is not allowed. This results in triggering an assertion failure instead of generating the wanted error message. Another, more annoying, problem is that if the allocation to generate the WAL segment name fails on OOM, then the failure would be escalated to a PANIC. This removes the routine and all its callers are replaced with a logic using a fixed-size buffer. This way, all the existing mistakes are fixed and future ones are prevented. Author: Masahiko Sawada Reviewed-by: Michael Paquier, Álvaro Herrera Discussion: https://postgr.es/m/CA+fd4k5gC9H4uoWMLg9K_QfNrnkkdEw+-AFveob9YX7z8JnKTA@mail.gmail.com --- src/backend/access/transam/xlogutils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/backend/access/transam/xlogutils.c') diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 446760ed6e7..14efbf37d61 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -776,7 +776,7 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, uint32 wa /* openSegment callback for WALRead */ static int -wal_segment_open(XLogSegNo nextSegNo, WALSegmentContext *segcxt, +wal_segment_open(XLogSegNo nextSegNo, WALSegmentContext * segcxt, TimeLineID *tli_p) { TimeLineID tli = *tli_p; @@ -944,7 +944,9 @@ void WALReadRaiseError(WALReadError *errinfo) { WALOpenSegment *seg = &errinfo->wre_seg; - char *fname = XLogFileNameP(seg->ws_tli, seg->ws_segno); + char fname[MAXFNAMELEN]; + + XLogFileName(fname, seg->ws_tli, seg->ws_segno, wal_segment_size); if (errinfo->wre_read < 0) { -- cgit v1.2.3