提交 d2c67198 编写于 作者: D Denis Smirnov 提交者: Ashwin Agrawal

Add missed NULL checks for XLogReaderAllocate

XLogReaderAllocate returns NULL if the xlogreader couldn't be
allocated. This NULL checks were forgotten in several places of
twophase.c and caused segmentation faults under heavy workloads.
上级 dd29616a
......@@ -1401,6 +1401,11 @@ FinishPreparedTransaction(const char *gid, bool isCommit, bool raiseErrorIfNotFo
* file descriptor here.
*/
xlogreader = XLogReaderAllocate(&read_local_xlog_page, NULL);
if (!xlogreader)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed while allocating an XLog reading processor.")));
tfRecord = XLogReadRecord(xlogreader, tfXLogRecPtr, &errormsg);
if (tfRecord == NULL)
......@@ -1687,6 +1692,11 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
}
xlogreader = XLogReaderAllocate(&read_local_xlog_page, NULL);
if (!xlogreader)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed while allocating an XLog reading processor.")));
while (tfXLogRecPtr != InvalidXLogRecPtr)
{
......@@ -1913,6 +1923,11 @@ RecoverPreparedTransactions(void)
char *errormsg;
xlogreader = XLogReaderAllocate(&read_local_xlog_page, NULL);
if (!xlogreader)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed while allocating an XLog reading processor.")));
if (crashRecoverPostCheckpointPreparedTransactions_map_ht != NULL)
{
......
......@@ -442,6 +442,11 @@ check_ao_record_present(unsigned char type, char *buf, Size len,
test_PrintLog("wal end record", walEnd, sendTime);
xlogreader = XLogReaderAllocate(&read_local_xlog_page, NULL);
if (!xlogreader)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed while allocating an XLog reading processor.")));
/*
* Find the first valid record at or after the given starting point.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册