v1-0001-Add-CLOBBER_FREED_MEM-to-shm_toc_allocate.patch

application/octet-stream

Filename: v1-0001-Add-CLOBBER_FREED_MEM-to-shm_toc_allocate.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #17619: AllocSizeIsValid violation in parallel hash join

Patch

Format: format-patch
Series: patch v1-0001
Subject: Add CLOBBER_FREED_MEM to shm_toc_allocate().
File+
src/backend/storage/ipc/shm_toc.c 9 1
From e3aefb062efdbee5afc06ffe912944ac48e14825 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <pg@bowt.ie>
Date: Tue, 27 Sep 2022 11:11:14 -0700
Subject: [PATCH v1] Add CLOBBER_FREED_MEM to shm_toc_allocate().

---
 src/backend/storage/ipc/shm_toc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/backend/storage/ipc/shm_toc.c b/src/backend/storage/ipc/shm_toc.c
index 0c9ef6442..bfcd8b09b 100644
--- a/src/backend/storage/ipc/shm_toc.c
+++ b/src/backend/storage/ipc/shm_toc.c
@@ -16,6 +16,7 @@
 #include "port/atomics.h"
 #include "storage/shm_toc.h"
 #include "storage/spin.h"
+#include "utils/memdebug.h"
 
 typedef struct shm_toc_entry
 {
@@ -92,6 +93,7 @@ shm_toc_allocate(shm_toc *toc, Size nbytes)
 	Size		allocated_bytes;
 	Size		nentry;
 	Size		toc_bytes;
+	void	   *ret;
 
 	/*
 	 * Make sure request is well-aligned.  XXX: MAXALIGN is not enough,
@@ -121,7 +123,13 @@ shm_toc_allocate(shm_toc *toc, Size nbytes)
 
 	SpinLockRelease(&toc->toc_mutex);
 
-	return ((char *) toc) + (total_bytes - allocated_bytes - nbytes);
+	ret = ((char *) toc) + (total_bytes - allocated_bytes - nbytes);
+
+#ifdef CLOBBER_FREED_MEMORY
+	wipe_mem(ret, nbytes);
+#endif
+
+	return ret;
 }
 
 /*
-- 
2.34.1