mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Repair bugs discussed in pghackers thread of 15 May 1999: creation of a
relcache entry no longer leaks a small amount of memory. index_endscan now releases all the memory acquired by index_beginscan, so callers of it should NOT pfree the scan descriptor anymore.
This commit is contained in:
34
src/backend/utils/cache/relcache.c
vendored
34
src/backend/utils/cache/relcache.c
vendored
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.83 1999/12/28 13:40:49 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.84 1999/12/30 05:05:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -378,31 +378,27 @@ static Relation
|
||||
AllocateRelationDesc(Relation relation, u_int natts,
|
||||
Form_pg_class relp)
|
||||
{
|
||||
Size len;
|
||||
Form_pg_class relationForm;
|
||||
|
||||
/* ----------------
|
||||
* allocate space for the relation tuple form
|
||||
* ----------------
|
||||
*/
|
||||
relationForm = (Form_pg_class)
|
||||
palloc((Size) (sizeof(FormData_pg_class)));
|
||||
relationForm = (Form_pg_class) palloc(sizeof(FormData_pg_class));
|
||||
|
||||
memmove((char *) relationForm, (char *) relp, CLASS_TUPLE_SIZE);
|
||||
memcpy((char *) relationForm, (char *) relp, CLASS_TUPLE_SIZE);
|
||||
|
||||
/* ----------------
|
||||
* allocate space for new relation descriptor, if needed
|
||||
*/
|
||||
len = sizeof(RelationData);
|
||||
|
||||
if (relation == NULL)
|
||||
relation = (Relation) palloc(len);
|
||||
relation = (Relation) palloc(sizeof(RelationData));
|
||||
|
||||
/* ----------------
|
||||
* clear new reldesc
|
||||
* ----------------
|
||||
*/
|
||||
MemSet((char *) relation, 0, len);
|
||||
MemSet((char *) relation, 0, sizeof(RelationData));
|
||||
|
||||
/* make sure relation is marked as having no open file yet */
|
||||
relation->rd_fd = -1;
|
||||
@ -745,13 +741,9 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
|
||||
u_int natts;
|
||||
Oid relid;
|
||||
Oid relam;
|
||||
Form_pg_class relp;
|
||||
|
||||
MemoryContext oldcxt;
|
||||
|
||||
HeapTuple pg_class_tuple;
|
||||
|
||||
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
|
||||
Form_pg_class relp;
|
||||
MemoryContext oldcxt;
|
||||
|
||||
/* ----------------
|
||||
* find the tuple in pg_class corresponding to the given relation id
|
||||
@ -764,11 +756,7 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
|
||||
* ----------------
|
||||
*/
|
||||
if (!HeapTupleIsValid(pg_class_tuple))
|
||||
{
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* get information from the pg_class_tuple
|
||||
@ -781,8 +769,10 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
|
||||
/* ----------------
|
||||
* allocate storage for the relation descriptor,
|
||||
* initialize relation->rd_rel and get the access method id.
|
||||
* The storage is allocated in memory context CacheCxt.
|
||||
* ----------------
|
||||
*/
|
||||
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
|
||||
relation = AllocateRelationDesc(oldrelation, natts, relp);
|
||||
relam = relation->rd_rel->relam;
|
||||
|
||||
@ -866,6 +856,8 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
|
||||
*/
|
||||
RelationCacheInsert(relation);
|
||||
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
|
||||
/* -------------------
|
||||
* free the memory allocated for pg_class_tuple
|
||||
* and for lock data pointed to by pg_class_tuple
|
||||
@ -873,8 +865,6 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
|
||||
*/
|
||||
heap_freetuple(pg_class_tuple);
|
||||
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
|
||||
return relation;
|
||||
}
|
||||
|
||||
@ -1764,7 +1754,6 @@ AttrDefaultFetch(Relation relation)
|
||||
ndef - found, RelationGetRelationName(relation));
|
||||
|
||||
index_endscan(sd);
|
||||
pfree(sd);
|
||||
index_close(irel);
|
||||
heap_close(adrel, AccessShareLock);
|
||||
}
|
||||
@ -1837,7 +1826,6 @@ RelCheckFetch(Relation relation)
|
||||
ncheck - found, RelationGetRelationName(relation));
|
||||
|
||||
index_endscan(sd);
|
||||
pfree(sd);
|
||||
index_close(irel);
|
||||
heap_close(rcrel, AccessShareLock);
|
||||
}
|
||||
|
Reference in New Issue
Block a user