server: Explicitly mark memory as undefined in mem_alloc wrapper.

Sebastian Lackner sebastian at fds-team.de
Tue Mar 7 19:50:45 CST 2017


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

The memset is hiding multiple places where uninitialized memory is
passed back to the user application. This patch tells Valgrind that
the memory is still uninitialized afterwards. If preferred, we can
also get rid of the memset.

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

diff --git a/server/object.c b/server/object.c
index ad22ec1e94b..5f83f09b258 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