From a071516a0f350da88235bb0964431c3839b910f1 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Sat, 4 Dec 2021 11:01:39 -0300 Subject: [PATCH] PG-286: Check for NULL return on hash_search before using object. Check if hash_search() function returns NULL before attempting to use the object in hash_entry_alloc(). --- hash_query.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hash_query.c b/hash_query.c index d6e4051..5074d5f 100644 --- a/hash_query.c +++ b/hash_query.c @@ -149,7 +149,9 @@ hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding) } /* Find or create an entry with desired hash code */ entry = (pgssEntry *) hash_search(pgss_hash, key, HASH_ENTER_NULL, &found); - if (!found) + if (entry == NULL) + pgsm_log_error("hash_entry_alloc: OUT OF MEMORY"); + else if (!found) { pgss->bucket_entry[pg_atomic_read_u64(&pgss->current_wbucket)]++; /* New entry, initialize it */ @@ -161,8 +163,6 @@ hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding) /* ... and don't forget the query text metadata */ entry->encoding = encoding; } - if (entry == NULL) - pgsm_log_error("hash_entry_alloc: OUT OF MEMORY"); return entry; }