Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e262755

Browse files
committed
Fix cache flush hazard in cache_record_field_properties().
We need to increment the refcount on the composite type's cached tuple descriptor while we do lookups of its column types. Otherwise a cache flush could occur and release the tuple descriptor before we're done with it. This fails reliably with -DCLOBBER_CACHE_ALWAYS, but the odds of a failure in a production build seem rather low (since the pfree'd descriptor typically wouldn't get scribbled on immediately). That may explain the lack of any previous reports. Buildfarm issue noted by Christian Ullrich. Back-patch to 9.1 where the bogus code was added.
1 parent ecdec47 commit e262755

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/backend/utils/cache/typcache.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ cache_record_field_properties(TypeCacheEntry *typentry)
648648
load_typcache_tupdesc(typentry);
649649
tupdesc = typentry->tupDesc;
650650

651+
/* Must bump the refcount while we do additional catalog lookups */
652+
IncrTupleDescRefCount(tupdesc);
653+
651654
/* Have each property if all non-dropped fields have the property */
652655
newflags = (TCFLAGS_HAVE_FIELD_EQUALITY |
653656
TCFLAGS_HAVE_FIELD_COMPARE);
@@ -671,6 +674,8 @@ cache_record_field_properties(TypeCacheEntry *typentry)
671674
break;
672675
}
673676
typentry->flags |= newflags;
677+
678+
DecrTupleDescRefCount(tupdesc);
674679
}
675680
typentry->flags |= TCFLAGS_CHECKED_FIELD_PROPERTIES;
676681
}

0 commit comments

Comments
 (0)