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

Commit73eba19

Browse files
committed
Fix another ancient memory-leak bug in relcache.c.
CheckConstraintFetch() leaked a cstring in the caller's context for eachCHECK constraint expression it copied into the relcache. Ordinarily thatisn't problematic, but it can be during CLOBBER_CACHE testing because somany reloads can happen during a single query; so complicate the codeslightly to allow freeing the cstring after use. Per testing on buildfarmmember barnacle.This is exactly like the leak fixed in AttrDefaultFetch() by commit078b2ed. (Yes, this time I did look forother instances of the same coding pattern :-(.) Like that patch, noback-patch, since it seems unlikely that there's any problem except undervery artificial test conditions.BTW, it strikes me that both of these places would require further workcomparable to commitab8c84d, if we eversupported defaults or check constraints on system catalogs: they bothassume they are copying into an empty relcache data structure, and thatconceivably wouldn't be the case during recursive reloading of a systemcatalog. This does not seem worth worrying about for the moment, sincethere is no near-term prospect of supporting any such thing. So I'lljust note the possibility for the archives' sake.
1 parent256bfb2 commit73eba19

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,8 +3552,6 @@ CheckConstraintFetch(Relation relation)
35523552
SysScanDescconscan;
35533553
ScanKeyDataskey[1];
35543554
HeapTuplehtup;
3555-
Datumval;
3556-
boolisnull;
35573555
intfound=0;
35583556

35593557
ScanKeyInit(&skey[0],
@@ -3568,6 +3566,9 @@ CheckConstraintFetch(Relation relation)
35683566
while (HeapTupleIsValid(htup=systable_getnext(conscan)))
35693567
{
35703568
Form_pg_constraintconform= (Form_pg_constraint)GETSTRUCT(htup);
3569+
Datumval;
3570+
boolisnull;
3571+
char*s;
35713572

35723573
/* We want check constraints only */
35733574
if (conform->contype!=CONSTRAINT_CHECK)
@@ -3590,8 +3591,11 @@ CheckConstraintFetch(Relation relation)
35903591
elog(ERROR,"null conbin for rel %s",
35913592
RelationGetRelationName(relation));
35923593

3593-
check[found].ccbin=MemoryContextStrdup(CacheMemoryContext,
3594-
TextDatumGetCString(val));
3594+
/* detoast and convert to cstring in caller's context */
3595+
s=TextDatumGetCString(val);
3596+
check[found].ccbin=MemoryContextStrdup(CacheMemoryContext,s);
3597+
pfree(s);
3598+
35953599
found++;
35963600
}
35973601

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp