Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9dab9ab

Browse files
committed
Repair memory leaks that caused CacheCxt to grow without bound. We
really ought to fix relcache entry construction so that it does notdo so much with CurrentMemoryContext = CacheCxt. As is, relativelyharmless leaks in either sequential or index scanning translate topermanent leaks if they occur when called from relcache build.For the moment, however, the path of least resistance is to repairall such leaks...
1 parentaa16179 commit9dab9ab

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.67 2000/04/12 17:14:45 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.68 2000/05/21 02:28:54 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -766,6 +766,9 @@ heap_endscan(HeapScanDesc scan)
766766
*/
767767
RelationDecrementReferenceCount(scan->rs_rd);
768768

769+
if (scan->rs_key)
770+
pfree(scan->rs_key);
771+
769772
pfree(scan);
770773
}
771774

‎src/backend/utils/cache/relcache.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.95 2000/04/12 17:15:54 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.96 2000/05/21 02:28:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -245,6 +245,9 @@ static bool criticalRelcacheBuild = false;
245245
*this is used by RelationBuildDesc to find a pg_class
246246
*tuple matching either a relation name or a relation id
247247
*as specified in buildinfo.
248+
*
249+
*NB: the returned tuple has been copied into palloc'd storage
250+
*and must eventually be freed with heap_freetuple.
248251
* --------------------------------
249252
*/
250253
staticHeapTuple
@@ -356,6 +359,8 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo)
356359

357360
heap_close(pg_class_desc,AccessShareLock);
358361

362+
/* The xxxIndexScan routines will have returned a palloc'd tuple. */
363+
359364
returnreturn_tuple;
360365
}
361366

@@ -519,9 +524,9 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo,
519524
relation->rd_att->attrs[attp->attnum-1]=
520525
(Form_pg_attribute)palloc(ATTRIBUTE_TUPLE_SIZE);
521526

522-
memmove((char*) (relation->rd_att->attrs[attp->attnum-1]),
523-
(char*)attp,
524-
ATTRIBUTE_TUPLE_SIZE);
527+
memcpy((char*) (relation->rd_att->attrs[attp->attnum-1]),
528+
(char*)attp,
529+
ATTRIBUTE_TUPLE_SIZE);
525530
need--;
526531
/* Update if this attribute have a constraint */
527532
if (attp->attnotnull)
@@ -571,26 +576,22 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
571576
intndef=0;
572577
inti;
573578

574-
#ifdef_DROP_COLUMN_HACK__
575-
boolcolumnDropped;
576-
577-
#endif/* _DROP_COLUMN_HACK__ */
578-
579579
constr->has_not_null= false;
580580

581581
attrel=heap_openr(AttributeRelationName,AccessShareLock);
582582

583583
for (i=1;i <=relation->rd_rel->relnatts;i++)
584584
{
585585
#ifdef_DROP_COLUMN_HACK__
586-
columnDropped= false;
586+
boolcolumnDropped= false;
587587
#endif/* _DROP_COLUMN_HACK__ */
588+
588589
atttup= (HeapTuple)AttributeRelidNumIndexScan(attrel,
589590
RelationGetRelid(relation),i);
590591

591592
if (!HeapTupleIsValid(atttup))
592-
#ifdef_DROP_COLUMN_HACK__
593593
{
594+
#ifdef_DROP_COLUMN_HACK__
594595
atttup= (HeapTuple)AttributeRelidNumIndexScan(attrel,
595596
RelationGetRelid(relation),DROPPED_COLUMN_INDEX(i));
596597
if (!HeapTupleIsValid(atttup))
@@ -599,21 +600,24 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
599600
RelationGetRelationName(relation));
600601
#ifdef_DROP_COLUMN_HACK__
601602
columnDropped= true;
602-
}
603603
#endif/* _DROP_COLUMN_HACK__ */
604-
attp= (Form_pg_attribute)GETSTRUCT(atttup);
604+
}
605605

606-
relation->rd_att->attrs[i-1]=
606+
relation->rd_att->attrs[i-1]=attp=
607607
(Form_pg_attribute)palloc(ATTRIBUTE_TUPLE_SIZE);
608608

609-
memmove((char*) (relation->rd_att->attrs[i-1]),
610-
(char*)attp,
611-
ATTRIBUTE_TUPLE_SIZE);
609+
memcpy((char*)attp,
610+
(char*) (Form_pg_attribute)GETSTRUCT(atttup),
611+
ATTRIBUTE_TUPLE_SIZE);
612+
613+
/* don't forget to free the tuple returned from xxxIndexScan */
614+
heap_freetuple(atttup);
612615

613616
#ifdef_DROP_COLUMN_HACK__
614617
if (columnDropped)
615618
continue;
616619
#endif/* _DROP_COLUMN_HACK__ */
620+
617621
/* Update if this attribute have a constraint */
618622
if (attp->attnotnull)
619623
constr->has_not_null= true;
@@ -1117,12 +1121,9 @@ formrdesc(char *relationName,
11171121
for (i=0;i<natts;i++)
11181122
{
11191123
relation->rd_att->attrs[i]= (Form_pg_attribute)palloc(ATTRIBUTE_TUPLE_SIZE);
1120-
1121-
MemSet((char*)relation->rd_att->attrs[i],0,
1124+
memcpy((char*)relation->rd_att->attrs[i],
1125+
(char*)&att[i],
11221126
ATTRIBUTE_TUPLE_SIZE);
1123-
memmove((char*)relation->rd_att->attrs[i],
1124-
(char*)&att[i],
1125-
ATTRIBUTE_TUPLE_SIZE);
11261127
}
11271128

11281129
/* ----------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp