From ddd96e1f211285e8561c673cad137ae10ea19d85 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 1 Jun 2001 20:07:16 +0000 Subject: [PATCH] Guard against malloc failure. Also, don't examine segP->lastBackend until we hold the spinlock. --- src/backend/storage/ipc/sinval.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/backend/storage/ipc/sinval.c b/src/backend/storage/ipc/sinval.c index f39b8f8c64..d60e6198f5 100644 --- a/src/backend/storage/ipc/sinval.c +++ b/src/backend/storage/ipc/sinval.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.31 2001/05/18 21:24:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.32 2001/06/01 20:07:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -283,15 +283,24 @@ GetSnapshotData(bool serializable) int index; int count = 0; + if (snapshot == NULL) + elog(ERROR, "Memory exhausted in GetSnapshotData"); + + snapshot->xmin = GetCurrentTransactionId(); + + SpinAcquire(SInvalLock); + /* * There can be no more than lastBackend active transactions, so this * is enough space: */ snapshot->xip = (TransactionId *) malloc(segP->lastBackend * sizeof(TransactionId)); - snapshot->xmin = GetCurrentTransactionId(); - - SpinAcquire(SInvalLock); + if (snapshot->xip == NULL) + { + SpinRelease(SInvalLock); + elog(ERROR, "Memory exhausted in GetSnapshotData"); + } /* * Unfortunately, we have to call ReadNewTransactionId() after