Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b8d478

Browse files
committed
Rework handling of OOM when allocating record buffer in XLOG reader.
Commit 2c03216 changed allocate_recordbuf() so that it uses a palloc to allocate the read buffer and fails immediately when an out-of-memory error shows up, even though its callers still expect that NULL is returned in that case. This bug is fixed making allocate_recordbuf() use a palloc_extended with MCXT_ALLOC_NO_OOM flag and return NULL in OOM case. Michael Paquier
1 parent 8c8a886 commit 9b8d478

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/access/transam/xlogreader.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ allocate_recordbuf(XLogReaderState *state, uint32 reclength)
146146

147147
if (state->readRecordBuf)
148148
pfree(state->readRecordBuf);
149-
state->readRecordBuf = (char *) palloc(newSize);
149+
state->readRecordBuf =
150+
(char *) palloc_extended(newSize, MCXT_ALLOC_NO_OOM);
151+
if (state->readRecordBuf == NULL)
152+
{
153+
state->readRecordBufSize = 0;
154+
return false;
155+
}
150156
state->readRecordBufSize = newSize;
151157
return true;
152158
}

0 commit comments

Comments
 (0)