Avoid potential relcache leak in objectaddress.c.

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.
This commit is contained in:
Robert Haas 2011-10-14 11:35:40 -04:00
parent ad30d36642
commit 393e828e31
1 changed files with 10 additions and 1 deletions

View 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. */