Avoid potential relcache leak in objectaddress.c.
authorRobert Haas <rhaas@postgresql.org>
Fri, 14 Oct 2011 15:35:40 +0000 (11:35 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 14 Oct 2011 15:35:40 +0000 (11:35 -0400)
Nobody using the missing_ok flag yet, but let's speculate that this will
be a better interface for future callers.

KaiGai Kohei, with some adjustments by me.

src/backend/catalog/objectaddress.c

index 6928835b6a718a88105783437cc34222ab2b55fe..395c11605a3872f4501fd98d375b7ccf5db5f151 100644 (file)
@@ -639,7 +639,8 @@ get_object_address_relobject(ObjectType objtype, List *objname,
         * Caller is expecting to get back the relation, even though we
         * didn't end up using it to find the rule.
         */
-       relation = heap_open(reloid, AccessShareLock);
+       if (OidIsValid(address.objectId))
+           relation = heap_open(reloid, AccessShareLock);
    }
    else
    {
@@ -677,6 +678,14 @@ get_object_address_relobject(ObjectType objtype, List *objname,
                address.objectId = InvalidOid;
                address.objectSubId = 0;
        }
+
+       /* Avoid relcache leak when object not found. */
+       if (!OidIsValid(address.objectId))
+       {
+           heap_close(relation, AccessShareLock);
+           relation = NULL;        /* department of accident prevention */
+           return address;
+       }
    }
 
    /* Done. */