Import some of memory manager debug facilities from PostgreSQL.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 8 Aug 2019 02:02:50 +0000 (11:02 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 8 Aug 2019 02:16:37 +0000 (11:16 +0900)
Now we can use CLOBBER_FREED_MEMORY, which is useful to detect
accesses to already pfreed memory.

src/include/utils/memdebug.h

index 0b955693e612aeda4f569e4b1e0719667b9fe27c..f7b08bbf1855cbfd259ba823c1e8ad2c26796530 100644 (file)
 #define VALGRIND_MEMPOOL_CHANGE(context, optr, nptr, size)     do {} while (0)
 #endif
 
-#endif   /* MEMDEBUG_H */
+#ifdef CLOBBER_FREED_MEMORY
+
+/* Wipe freed memory for debugging purposes */
+static inline void
+wipe_mem(void *ptr, size_t size)
+{
+       VALGRIND_MAKE_MEM_UNDEFINED(ptr, size);
+       memset(ptr, 0x7F, size);
+       VALGRIND_MAKE_MEM_NOACCESS(ptr, size);
+}
+
+#endif /* CLOBBER_FREED_MEMORY */
+
+#endif   /* MEMDEBUG_H */
\ No newline at end of file