-LRN: Poisoning:
authorChristian Grothoff <christian@grothoff.org>
Sat, 23 Jun 2012 22:30:43 +0000 (22:30 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 23 Jun 2012 22:30:43 +0000 (22:30 +0000)
  Poisons memory before freeing it. It uses msize() CRT function,
which (i believe) is not available on other platforms. This patch was
intended to make the output of the next patch (see below) more apparent.

src/util/common_allocation.c

index 5e1f75eb7c78929becd694e02d64ab657a137222..801eeeebc349216ca92441e25e371645c6bbd300 100644 (file)
@@ -197,6 +197,17 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
 #ifdef W32_MEM_LIMIT
   ptr = &((size_t *) ptr)[-1];
   mem_used -= *((size_t *) ptr);
+#endif
+#if WINDOWS
+#if ENABLE_POISONING
+  {
+    size_t i;
+    char baadfood[4] = "\xBA\xAD\xF0\x0D";
+    size_t s = _msize (ptr);
+    for (i = 0; i < s; i++)
+      ((char *) ptr)[i] = baadfood[i % 4];
+  }
+#endif
 #endif
   free (ptr);
 }