]> granicus.if.org Git - postgresql/commitdiff
Check for malloc failure.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Jun 2001 20:29:43 +0000 (20:29 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Jun 2001 20:29:43 +0000 (20:29 +0000)
src/backend/utils/cache/inval.c
src/backend/utils/init/miscinit.c
src/backend/utils/misc/guc-file.l

index bb3c2822232dedd98e89d52e62d2d5e54f0c85d9..b15eac025eadde16cafe1489e4fdd0ec13ab1234 100644 (file)
@@ -34,7 +34,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.42 2001/03/22 03:59:57 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.43 2001/06/01 20:23:06 tgl Exp $
  *
  * Note - this code is real crufty... badly needs a rewrite to improve
  * readability and portability.  (Shouldn't assume Oid == Index, for example)
@@ -53,7 +53,6 @@
 
 /*
  *             private invalidation structures
- *
  */
 
 typedef struct InvalidationUserData
@@ -102,7 +101,6 @@ typedef InvalidationMessageData *InvalidationMessage;
 
 /*
  *             variables and macros
- *
  */
 
 /*
@@ -152,7 +150,6 @@ static void InvalidationMessageRegisterSharedInvalid(InvalidationMessage message
 /*
  *             InvalidationEntryAllocate
  *                             Allocates an invalidation entry.
- *
  */
 static InvalidationEntry
 InvalidationEntryAllocate(uint16 size)
@@ -161,6 +158,8 @@ InvalidationEntryAllocate(uint16 size)
 
        entryDataP = (InvalidationEntryData *)
                malloc(sizeof(char *) + size);  /* XXX alignment */
+       if (entryDataP == NULL)
+               elog(ERROR, "Memory exhausted in InvalidationEntryAllocate");
        entryDataP->nextP = NULL;
        return (Pointer) &entryDataP->userData;
 }
@@ -169,7 +168,6 @@ InvalidationEntryAllocate(uint16 size)
  *             LocalInvalidRegister
  *                Link an invalidation entry into a chain of them.  Really ugly
  *                coding here.
- *
  */
 static LocalInvalid
 LocalInvalidRegister(LocalInvalid invalid,
@@ -187,7 +185,6 @@ LocalInvalidRegister(LocalInvalid invalid,
  *             LocalInvalidInvalidate
  *                             Processes, then frees all entries in a local cache
  *                             invalidation list unless freemember parameter is false.
- *
  */
 static void
 LocalInvalidInvalidate(LocalInvalid invalid,
@@ -258,7 +255,6 @@ elog(DEBUG, "CacheIdRegisterLocalRollback(%d, %d, [%d, %d])", \
 
 /*
  *             CacheIdRegisterSpecifiedLocalInvalid
- *
  */
 static LocalInvalid
 CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
@@ -270,14 +266,12 @@ CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
 
        /*
         * debugging stuff
-        *
         */
        CacheIdRegisterSpecifiedLocalInvalid_DEBUG1;
 
        /*
         * create a message describing the system catalog tuple we wish to
         * invalidate.
-        *
         */
        message = (InvalidationMessage)
                InvalidationEntryAllocate(sizeof(InvalidationMessageData));
@@ -290,7 +284,6 @@ CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
 
        /*
         * Add message to linked list of unprocessed messages.
-        *
         */
        invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message);
        return invalid;
@@ -298,7 +291,6 @@ CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
 
 /*
  *             CacheIdRegisterLocalInvalid
- *
  */
 static void
 CacheIdRegisterLocalInvalid(int cacheId,
@@ -308,20 +300,17 @@ CacheIdRegisterLocalInvalid(int cacheId,
 
        /*
         * debugging stuff
-        *
         */
        CacheIdRegisterLocalInvalid_DEBUG1;
 
        /*
         * Add message to InvalidForall linked list.
-        *
         */
        InvalidForall = CacheIdRegisterSpecifiedLocalInvalid(InvalidForall,
                                                                                        cacheId, hashIndex, pointer);
 
        /*
         * Add message to InvalidLocal linked list.
-        *
         */
        InvalidLocal = CacheIdRegisterSpecifiedLocalInvalid(InvalidLocal,
                                                                                        cacheId, hashIndex, pointer);
@@ -329,7 +318,6 @@ CacheIdRegisterLocalInvalid(int cacheId,
 
 /*
  *             CacheIdRegisterLocalRollback
- *
  */
 static void
 CacheIdRegisterLocalRollback(int cacheId,
@@ -339,13 +327,11 @@ CacheIdRegisterLocalRollback(int cacheId,
 
        /*
         * debugging stuff
-        *
         */
        CacheIdRegisterLocalRollback_DEBUG1;
 
        /*
         * Add message to RollbackStack linked list.
-        *
         */
        RollbackStack = CacheIdRegisterSpecifiedLocalInvalid(
                                                         RollbackStack, cacheId, hashIndex, pointer);
@@ -353,7 +339,6 @@ CacheIdRegisterLocalRollback(int cacheId,
 
 /*
  *             RelationIdRegisterSpecifiedLocalInvalid
- *
  */
 static LocalInvalid
 RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
@@ -363,7 +348,6 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
 
        /*
         * debugging stuff
-        *
         */
 #ifdef INVALIDDEBUG
        elog(DEBUG, "RelationRegisterSpecifiedLocalInvalid(%u, %u)", relationId,
@@ -373,7 +357,6 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
        /*
         * create a message describing the relation descriptor we wish to
         * invalidate.
-        *
         */
        message = (InvalidationMessage)
                InvalidationEntryAllocate(sizeof(InvalidationMessageData));
@@ -384,7 +367,6 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
 
        /*
         * Add message to linked list of unprocessed messages.
-        *
         */
        invalid = LocalInvalidRegister(invalid, (InvalidationEntry) message);
        return invalid;
@@ -392,7 +374,6 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
 
 /*
  *             RelationIdRegisterLocalInvalid
- *
  */
 static void
 RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
@@ -400,7 +381,6 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
 
        /*
         * debugging stuff
-        *
         */
 #ifdef INVALIDDEBUG
        elog(DEBUG, "RelationRegisterLocalInvalid(%u, %u)", relationId,
@@ -409,14 +389,12 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
 
        /*
         * Add message to InvalidForall linked list.
-        *
         */
        InvalidForall = RelationIdRegisterSpecifiedLocalInvalid(InvalidForall,
                                                                                                   relationId, objectId);
 
        /*
         * Add message to InvalidLocal linked list.
-        *
         */
        InvalidLocal = RelationIdRegisterSpecifiedLocalInvalid(InvalidLocal,
                                                                                                   relationId, objectId);
@@ -424,7 +402,6 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
 
 /*
  *             RelationIdRegisterLocalRollback
- *
  */
 static void
 RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
@@ -432,7 +409,6 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
 
        /*
         * debugging stuff
-        *
         */
 #ifdef INVALIDDEBUG
        elog(DEBUG, "RelationRegisterLocalRollback(%u, %u)", relationId,
@@ -441,7 +417,6 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
 
        /*
         * Add message to RollbackStack linked list.
-        *
         */
        RollbackStack = RelationIdRegisterSpecifiedLocalInvalid(
                                                                        RollbackStack, relationId, objectId);
@@ -453,7 +428,6 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
  *             This routine can invalidate a tuple in a system catalog cache
  *             or a cached relation descriptor.  You pay your money and you
  *             take your chances...
- *
  */
 #ifdef INVALIDDEBUG
 #define CacheIdInvalidate_DEBUG1 \
@@ -472,7 +446,6 @@ CacheIdInvalidate(Index cacheId,
        /*
         * assume that if the item pointer is valid, then we are invalidating
         * an item in the specified system catalog cache.
-        *
         */
        if (ItemPointerIsValid(pointer))
        {
@@ -485,7 +458,6 @@ CacheIdInvalidate(Index cacheId,
        /*
         * if the cacheId is the oid of any of the following system relations,
         * then assume we are invalidating a relation descriptor
-        *
         */
        if (cacheId == RelOid_pg_class)
        {
@@ -501,7 +473,6 @@ CacheIdInvalidate(Index cacheId,
 
        /*
         * Yow! the caller asked us to invalidate something else.
-        *
         */
        elog(FATAL, "CacheIdInvalidate: cacheId=%d relation id?", cacheId);
 }
@@ -512,7 +483,6 @@ CacheIdInvalidate(Index cacheId,
  *             This blows away all tuples in the system catalog caches and
  *             all the cached relation descriptors (and closes their files too).
  *             Relation descriptors that have positive refcounts are then rebuilt.
- *
  */
 static void
 ResetSystemCaches(void)
@@ -523,7 +493,6 @@ ResetSystemCaches(void)
 
 /*
  *             InvalidationMessageRegisterSharedInvalid
- *
  */
 #ifdef INVALIDDEBUG
 #define InvalidationMessageRegisterSharedInvalid_DEBUG1 \
@@ -575,7 +544,6 @@ InvalidationMessageRegisterSharedInvalid(InvalidationMessage message)
 
 /*
  *             InvalidationMessageCacheInvalidate
- *
  */
 #ifdef INVALIDDEBUG
 #define InvalidationMessageCacheInvalidate_DEBUG1 \
@@ -624,7 +592,6 @@ InvalidationMessageCacheInvalidate(InvalidationMessage message)
 
 /*
  *             PrepareToInvalidateRelationCache
- *
  */
 static void
 PrepareToInvalidateRelationCache(Relation relation,
@@ -636,13 +603,11 @@ PrepareToInvalidateRelationCache(Relation relation,
 
        /*
         * get the relation object id
-        *
         */
        relationId = RelationGetRelid(relation);
 
        /*
         * is it one of the ones we need to send an SI message for?
-        *
         */
        if (relationId == RelOid_pg_class)
                objectId = tuple->t_data->t_oid;
@@ -653,7 +618,6 @@ PrepareToInvalidateRelationCache(Relation relation,
 
        /*
         * register the relcache-invalidation action in the appropriate list
-        *
         */
        Assert(PointerIsValid(function));
 
@@ -674,7 +638,6 @@ DiscardInvalid(void)
 
        /*
         * debugging stuff
-        *
         */
 #ifdef INVALIDDEBUG
        elog(DEBUG, "DiscardInvalid called");
@@ -697,7 +660,6 @@ RegisterInvalid(bool send)
 
        /*
         * debugging stuff
-        *
         */
 #ifdef INVALIDDEBUG
        elog(DEBUG, "RegisterInvalid(%d) called", send);
@@ -705,7 +667,6 @@ RegisterInvalid(bool send)
 
        /*
         * Process and free the current list of inval messages.
-        *
         */
 
        DiscardInvalidStack(&InvalidLocal);
@@ -741,7 +702,6 @@ ImmediateLocalInvalidation(bool send)
 
        /*
         * debugging stuff
-        *
         */
 #ifdef INVALIDDEBUG
        elog(DEBUG, "ImmediateLocalInvalidation(%d) called", send);
@@ -749,7 +709,6 @@ ImmediateLocalInvalidation(bool send)
 
        /*
         * Process and free the local list of inval messages.
-        *
         */
 
        if (send)
@@ -801,7 +760,6 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple,
 
        /*
         * sanity checks
-        *
         */
        Assert(RelationIsValid(relation));
        Assert(HeapTupleIsValid(tuple));
@@ -813,14 +771,12 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple,
         * We only need to worry about invalidation for tuples that are in
         * system relations; user-relation tuples are never in catcaches and
         * can't affect the relcache either.
-        *
         */
        if (!IsSystemRelationName(NameStr(RelationGetForm(relation)->relname)))
                return;
 
        /*
         * debugging stuff
-        *
         */
        PrepareForTupleInvalidation_DEBUG1;
 
index e8ad53d1bd96a9badc1c133a4f9745985418ef64..544b57ff1d63707d3a0c489ac83b8fbd17733dc1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.67 2001/05/18 17:49:52 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.68 2001/06/01 20:27:41 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -143,14 +143,18 @@ SetDataDir(const char *dir)
                }
 
                new = malloc(strlen(buf) + 1 + strlen(dir) + 1);
+               if (!new)
+                       elog(FATAL, "out of memory");
                sprintf(new, "%s/%s", buf, dir);
                free(buf);
        }
        else
+       {
                new = strdup(dir);
+               if (!new)
+                       elog(FATAL, "out of memory");
+       }
 
-       if (!new)
-               elog(FATAL, "out of memory");
        DataDir = new;
 }
 
@@ -278,10 +282,15 @@ SetCharSet()
        {
                map_file = (char *) malloc((strlen(DataDir) +
                                                                        strlen(p) + 2) * sizeof(char));
+               if (! map_file)
+                       elog(FATAL, "out of memory");
                sprintf(map_file, "%s/%s", DataDir, p);
                file = AllocateFile(map_file, PG_BINARY_R);
                if (file == NULL)
+               {
+                       free(map_file);
                        return;
+               }
                eof = false;
                while (!eof)
                {
index 0367e158762bf82f7b4516415ada9d859a6610a5..cb39525df928fa38519c3d6659fb50bbeed09e63 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.6 2001/01/24 19:01:31 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.7 2001/06/01 20:29:43 tgl Exp $
  */
 
 %{
@@ -324,6 +324,8 @@ GUC_scanstr(char *s)
        len = strlen(s);
 
        newStr = malloc(len + 1);       /* string cannot get longer */
+       if (newStr == NULL)
+               elog(FATAL, "out of memory");
 
        for (i = 0, j = 0; i < len; i++)
        {