1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Fix resource owner code to generate catcache and relcache leak warnings

when open references remain during normal cleanup of a resource owner.
This restores the system's ability to warn about leaks to what it was
before 8.0.  Not really a user-level bug, but helpful for development.
This commit is contained in:
Tom Lane
2005-03-25 18:30:28 +00:00
parent 6b7ef076b5
commit 08890b407e
3 changed files with 60 additions and 9 deletions

View File

@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/resowner/resowner.c,v 1.10 2005/03/04 20:21:06 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/resowner/resowner.c,v 1.11 2005/03/25 18:30:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -87,6 +87,7 @@ static void ResourceOwnerReleaseInternal(ResourceOwner owner,
ResourceReleasePhase phase,
bool isCommit,
bool isTopLevel);
static void PrintRelCacheLeakWarning(Relation rel);
/*****************************************************************************
@ -231,7 +232,11 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
* iterate till there are none.
*/
while (owner->nrelrefs > 0)
{
if (isCommit)
PrintRelCacheLeakWarning(owner->relrefs[owner->nrelrefs - 1]);
RelationClose(owner->relrefs[owner->nrelrefs - 1]);
}
}
}
else if (phase == RESOURCE_RELEASE_LOCKS)
@ -284,9 +289,17 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
* to iterate till there are none. Ditto for catcache lists.
*/
while (owner->ncatrefs > 0)
{
if (isCommit)
PrintCatCacheLeakWarning(owner->catrefs[owner->ncatrefs - 1]);
ReleaseCatCache(owner->catrefs[owner->ncatrefs - 1]);
}
while (owner->ncatlistrefs > 0)
{
if (isCommit)
PrintCatCacheListLeakWarning(owner->catlistrefs[owner->ncatlistrefs - 1]);
ReleaseCatCacheList(owner->catlistrefs[owner->ncatlistrefs - 1]);
}
}
/* Clean up index scans too */
ReleaseResources_gist();
@ -746,3 +759,13 @@ ResourceOwnerForgetRelationRef(ResourceOwner owner, Relation rel)
elog(ERROR, "relcache reference %s is not owned by resource owner %s",
RelationGetRelationName(rel), owner->name);
}
/*
* Debugging subroutine
*/
static void
PrintRelCacheLeakWarning(Relation rel)
{
elog(WARNING, "relcache reference leak: relation \"%s\" not closed",
RelationGetRelationName(rel));
}