summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/relcache.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-05-22 17:29:45 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-05-22 17:29:45 +0000
commit63448825fb041704554849cbfac00f022540936f (patch)
tree16655952d291ab5710d28eb6ad818e7267f842c1 /src/backend/utils/cache/relcache.c
parentce362bf8bee14c8589aa10649a1e3e516ed9e3e7 (diff)
Make RelationForgetRelation error out if the relcache entry has nonzero
reference count. This avoids leaving dangling pointers around, as in recent bug report against sequences (bug# 671).
Diffstat (limited to 'src/backend/utils/cache/relcache.c')
-rw-r--r--src/backend/utils/cache/relcache.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 16a38df83d3..938678476a4 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.151 2002/01/16 17:34:42 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.151.2.1 2002/05/22 17:29:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1755,35 +1755,39 @@ RelationForgetRelation(Oid rid)
RelationIdCacheLookup(rid, relation);
- if (PointerIsValid(relation))
+ if (!PointerIsValid(relation))
+ return; /* not in cache, nothing to do */
+
+ if (!RelationHasReferenceCountZero(relation))
+ elog(ERROR, "RelationForgetRelation: relation %u is still open", rid);
+
+ /* If local, remove from list */
+ if (relation->rd_myxactonly)
{
- if (relation->rd_myxactonly)
- {
- List *curr;
- List *prev = NIL;
+ List *curr;
+ List *prev = NIL;
- foreach(curr, newlyCreatedRelns)
- {
- Relation reln = lfirst(curr);
+ foreach(curr, newlyCreatedRelns)
+ {
+ Relation reln = lfirst(curr);
- Assert(reln != NULL && reln->rd_myxactonly);
- if (RelationGetRelid(reln) == rid)
- break;
- prev = curr;
- }
- if (curr == NIL)
- elog(FATAL, "Local relation %s not found in list",
- RelationGetRelationName(relation));
- if (prev == NIL)
- newlyCreatedRelns = lnext(newlyCreatedRelns);
- else
- lnext(prev) = lnext(curr);
- pfree(curr);
+ Assert(reln != NULL && reln->rd_myxactonly);
+ if (RelationGetRelid(reln) == rid)
+ break;
+ prev = curr;
}
-
- /* Unconditionally destroy the relcache entry */
- RelationClearRelation(relation, false);
+ if (curr == NIL)
+ elog(ERROR, "Local relation %s not found in list",
+ RelationGetRelationName(relation));
+ if (prev == NIL)
+ newlyCreatedRelns = lnext(newlyCreatedRelns);
+ else
+ lnext(prev) = lnext(curr);
+ pfree(curr);
}
+
+ /* Unconditionally destroy the relcache entry */
+ RelationClearRelation(relation, false);
}
/*