summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-11-10 11:00:13 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:05:42 -0500
commit099d8cc9722e04f31217f883ce4420945c22ae04 (patch)
tree085676fdc541a5e0b8d3a21f228165dfb9a9aa1c
parent5805c780dc6d78c2cc4a86d07155db807a80bac7 (diff)
downloadsamba-099d8cc9722e04f31217f883ce4420945c22ae04.tar.gz
samba-099d8cc9722e04f31217f883ce4420945c22ae04.tar.bz2
samba-099d8cc9722e04f31217f883ce4420945c22ae04.zip
r3656: allow easy testing of the "realloc changes the pointer" type of problem that abartlet
recently fixed. (This used to be commit 70e53a21f25360d3421758f5c37972ebc2337a9c)
-rw-r--r--source4/lib/talloc.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/source4/lib/talloc.c b/source4/lib/talloc.c
index 239958258b..0b1f5b7cb5 100644
--- a/source4/lib/talloc.c
+++ b/source4/lib/talloc.c
@@ -40,6 +40,11 @@
#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;