]> granicus.if.org Git - postgresql/commitdiff
Rework handling of OOM when allocating record buffer in XLOG reader.
authorFujii Masao <fujii@postgresql.org>
Fri, 3 Apr 2015 09:29:38 +0000 (18:29 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 3 Apr 2015 09:29:38 +0000 (18:29 +0900)
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

src/backend/access/transam/xlogreader.c

index ba7dfcc0287f7178b13cd1a2713a119b42b3ee71..ffdc9753ad739c14fcce3f587b6d581df59c7ef7 100644 (file)
@@ -146,7 +146,13 @@ allocate_recordbuf(XLogReaderState *state, uint32 reclength)
 
        if (state->readRecordBuf)
                pfree(state->readRecordBuf);
-       state->readRecordBuf = (char *) palloc(newSize);
+       state->readRecordBuf =
+               (char *) palloc_extended(newSize, MCXT_ALLOC_NO_OOM);
+       if (state->readRecordBuf == NULL)
+       {
+               state->readRecordBufSize = 0;
+               return false;
+       }
        state->readRecordBufSize = newSize;
        return true;
 }