r3656: allow easy testing of the "realloc changes the pointer" type of problem that...
authorAndrew Tridgell <tridge@samba.org>
Wed, 10 Nov 2004 11:00:13 +0000 (11:00 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:05:42 +0000 (13:05 -0500)
recently fixed.
(This used to be commit 70e53a21f25360d3421758f5c37972ebc2337a9c)

source4/lib/talloc.c

index 239958258bbed688ee5198a01f7bb87cb687c66a..0b1f5b7cb55148813c5e1f036a810a26cd1eb302 100644 (file)
 #include "includes.h"
 #endif
 
+/* use this to force every realloc to change the pointer, to stress test
+   code that might not cope */
+#define ALWAYS_REALLOC 0
+
+
 #define MAX_TALLOC_SIZE 0x10000000
 #define TALLOC_MAGIC 0xe814ec4f
 #define TALLOC_MAGIC_FREE 0x7faebef3
@@ -538,7 +543,15 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
        /* by resetting magic we catch users of the old memory */
        tc->magic = TALLOC_MAGIC_FREE;
 
+#if ALWAYS_REALLOC
+       new_ptr = malloc(size + sizeof(*tc));
+       if (new_ptr) {
+               memcpy(new_ptr, tc, tc->size + sizeof(*tc));
+               free(tc);
+       }
+#else
        new_ptr = realloc(tc, size + sizeof(*tc));
+#endif
        if (!new_ptr) { 
                tc->magic = TALLOC_MAGIC; 
                return NULL;