diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2021-09-15 11:59:34 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2021-09-15 12:15:04 +0200 |
commit | 851ff9335742d22a3cb1a5ab789208e4ee01dcef (patch) | |
tree | 10d5849ab8508dd08bb4ee7c4886fe53fbf9f5c2 /src/backend/utils/adt/arrayfuncs.c | |
parent | 379591fecf7c1011b72ddc0ffceae7a3f18b8320 (diff) | |
download | postgresql-851ff9335742d22a3cb1a5ab789208e4ee01dcef.tar.gz postgresql-851ff9335742d22a3cb1a5ab789208e4ee01dcef.zip |
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.
Discussion: https://www.postgresql.org/message-id/flat/17158-8a2ba823982537a4%40postgresql.org
Diffstat (limited to 'src/backend/utils/adt/arrayfuncs.c')
-rw-r--r-- | src/backend/utils/adt/arrayfuncs.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index bc2f30bae15..660e854e93f 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 = palloc0(sizeof(*record_typentry)); + record_typentry->type_id = element_type; /* fill in what we need below */ record_typentry->typlen = typentry->typlen; |