server: Explicitly mark memory as undefined in mem_alloc wrapper. (v2)

Sebastian Lackner sebastian at fds-team.de
Tue Mar 7 21:40:47 CST 2017


Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---

Changes in v2:
* Use size_t instead of SIZE_T.

 server/object.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/server/object.c b/server/object.c
index ad22ec1e94b..e43fe3f2173 100644
--- a/server/object.c
+++ b/server/object.c
@@ -28,6 +28,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdarg.h>
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+#include <valgrind/memcheck.h>
+#endif
 
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
@@ -92,11 +95,22 @@ void close_objects(void)
 
 /*****************************************************************/
 
+/* mark a block of memory as uninitialized for debugging purposes */
+static inline void mark_block_uninitialized( void *ptr, size_t size )
+{
+    memset( ptr, 0x55, size );
+#if defined(VALGRIND_MAKE_MEM_UNDEFINED)
+    VALGRIND_DISCARD( VALGRIND_MAKE_MEM_UNDEFINED( ptr, size ));
+#elif defined(VALGRIND_MAKE_WRITABLE)
+    VALGRIND_DISCARD( VALGRIND_MAKE_WRITABLE( ptr, size ));
+#endif
+}
+
 /* malloc replacement */
 void *mem_alloc( size_t size )
 {
     void *ptr = malloc( size );
-    if (ptr) memset( ptr, 0x55, size );
+    if (ptr) mark_block_uninitialized( ptr, size );
     else set_error( STATUS_NO_MEMORY );
     return ptr;
 }
-- 
2.11.0



More information about the wine-patches mailing list