robustify_memoize_code.patch

text/plain

Filename: robustify_memoize_code.patch
Type: text/plain
Part: 1
Message: Re: BUG #17512: Process running query fails with SIGSEV - nodeMemoize.c:349

Patch

Format: unified
File+
src/backend/executor/nodeMemoize.c 7 3
diff --git a/src/backend/executor/nodeMemoize.c b/src/backend/executor/nodeMemoize.c
index f7be4fc31f..ca06f7c1c1 100644
--- a/src/backend/executor/nodeMemoize.c
+++ b/src/backend/executor/nodeMemoize.c
@@ -446,9 +446,13 @@ cache_reduce_memory(MemoizeState *mstate, MemoizeKey *specialkey)
 		 */
 		entry = memoize_lookup(mstate->hashtable, NULL);
 
-		/* A good spot to check for corruption of the table and LRU list. */
-		Assert(entry != NULL);
-		Assert(entry->key == key);
+		/*
+		 * Sanity check that we found the entry belonging to the LRU list
+		 * item.  A misbehaving hash or equality function could cause the
+		 * entry not to be found.
+		 */
+		if (unlikely(entry == NULL || entry->key != key))
+			elog(ERROR, "unable to find memoization table entry");
 
 		/*
 		 * If we're being called to free memory while the cache is being