From 0475e686f5d2fb3aff7ec35c29f8ffb23e1d363b Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 14 Sep 2021 16:37:43 +0200 Subject: [PATCH] Fix hash_array Commit a3d2b1bbe904b0ca8d9fdde20f25295ff3e21f79 neglected to initialize the type_id field of the synthesized type cache entry, so it would make a new one on every call. Also, better use the per-function memory context for this; otherwise it leaks memory. --- src/backend/utils/adt/arrayfuncs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index bc2f30bae1..6bb6c70d11 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -3992,13 +3992,14 @@ hash_array(PG_FUNCTION_ARGS) MemoryContext oldcontext; TypeCacheEntry *record_typentry; - oldcontext = MemoryContextSwitchTo(CacheMemoryContext); + oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt); /* * Make fake type cache entry structure. Note that we can't just * modify typentry, since that points directly into the type cache. */ record_typentry = palloc(sizeof(*record_typentry)); + record_typentry->type_id = element_type; /* fill in what we need below */ record_typentry->typlen = typentry->typlen; -- 2.33.0