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:07:31 +0000 (11:07 +0900)
Now we can use CLOBBER_FREED_MEMORY, which is useful to detect
accesses to already pfreed memory.

src/include/utils/memdebug.h

index d258935ffe5b8b67dc5caf5be1a5b69f2b5a18bf..f28341d27d0fc868afe156af43f032f9ae3f8a48 100644 (file)
 #define VALGRIND_MEMPOOL_CHANGE(context, optr, nptr, size)     do {} while (0)
 #endif
 
+#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 */