1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Add some marginal tweaks to eliminate memory leakages associated with

subtransactions.  Trivial subxacts (such as a plpgsql exception block
containing no database access) now demonstrably leak zero bytes.
This commit is contained in:
Tom Lane
2004-09-16 20:17:49 +00:00
parent 86fff990b2
commit 257cccbe5e
6 changed files with 118 additions and 16 deletions

View File

@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.57 2004/08/29 05:06:51 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.58 2004/09/16 20:17:33 tgl Exp $
*
* NOTE:
* This is a new (Feb. 05, 1999) implementation of the allocation set
@@ -205,6 +205,7 @@ static void AllocSetInit(MemoryContext context);
static void AllocSetReset(MemoryContext context);
static void AllocSetDelete(MemoryContext context);
static Size AllocSetGetChunkSpace(MemoryContext context, void *pointer);
static bool AllocSetIsEmpty(MemoryContext context);
static void AllocSetStats(MemoryContext context);
#ifdef MEMORY_CONTEXT_CHECKING
@@ -222,6 +223,7 @@ static MemoryContextMethods AllocSetMethods = {
AllocSetReset,
AllocSetDelete,
AllocSetGetChunkSpace,
AllocSetIsEmpty,
AllocSetStats
#ifdef MEMORY_CONTEXT_CHECKING
,AllocSetCheck
@@ -991,6 +993,26 @@ AllocSetGetChunkSpace(MemoryContext context, void *pointer)
return chunk->size + ALLOC_CHUNKHDRSZ;
}
/*
* AllocSetIsEmpty
* Is an allocset empty of any allocated space?
*/
static bool
AllocSetIsEmpty(MemoryContext context)
{
AllocSet set = (AllocSet) context;
/*
* For now, we say "empty" only if the context never contained any
* space at all. We could examine the freelists to determine if all
* space has been freed, but it's not really worth the trouble for
* present uses of this functionality.
*/
if (set->blocks == NULL)
return true;
return false;
}
/*
* AllocSetStats
* Displays stats about memory consumption of an allocset.

View File

@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.50 2004/08/29 05:06:51 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.51 2004/09/16 20:17:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -291,6 +291,25 @@ GetMemoryChunkContext(void *pointer)
return header->context;
}
/*
* MemoryContextIsEmpty
* Is a memory context empty of any allocated space?
*/
bool
MemoryContextIsEmpty(MemoryContext context)
{
AssertArg(MemoryContextIsValid(context));
/*
* For now, we consider a memory context nonempty if it has any children;
* perhaps this should be changed later.
*/
if (context->firstchild != NULL)
return false;
/* Otherwise use the type-specific inquiry */
return (*context->methods->is_empty) (context);
}
/*
* MemoryContextStats
* Print statistics about the named context and all its descendants.
@@ -662,7 +681,6 @@ void
pgport_pfree(void *pointer)
{
pfree(pointer);
return;
}
#endif
#endif /* WIN32 */