]> granicus.if.org Git - postgresql/commitdiff
Guard against malloc failure. Also, don't examine segP->lastBackend
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Jun 2001 20:07:16 +0000 (20:07 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Jun 2001 20:07:16 +0000 (20:07 +0000)
until we hold the spinlock.

src/backend/storage/ipc/sinval.c

index f39b8f8c648284cfb31a7bd94bf8202b798088a3..d60e6198f51334bc138177eb0f8bc79c4fbd9e93 100644 (file)
@@ -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