r6845: make the talloc header align to 40 bytes, which costs us an extra 4
authorAndrew Tridgell <tridge@samba.org>
Tue, 17 May 2005 05:48:30 +0000 (05:48 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:50 +0000 (13:16 -0500)
bytes per allocation, but makes it much more portable
(This used to be commit 257027a571da254c16b0b456cb1cbec284d7fda0)

source4/lib/talloc/talloc.c

index e0f4cf9aff60b1029e6ac14cd83b079cf0ea33c5..6b6eb87f211524e3169bd318ee1e4764f3526cc0 100644 (file)
@@ -97,17 +97,20 @@ struct talloc_chunk {
        struct talloc_chunk *parent, *child;
        struct talloc_reference_handle *refs;
        size_t size;
-       unsigned magic;
        talloc_destructor_t destructor;
        const char *name;
+       union {
+               unsigned magic;
+               double align_dummy;
+       } u;
 };
 
 /* panic if we get a bad magic value */
 static struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr)
 {
        struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, ptr)-1;
-       if (tc->magic != TALLOC_MAGIC) { 
-               if (tc->magic == TALLOC_MAGIC_FREE) {
+       if (tc->u.magic != TALLOC_MAGIC) { 
+               if (tc->u.magic == TALLOC_MAGIC_FREE) {
                        TALLOC_ABORT("Bad talloc magic value - double free"); 
                } else {
                        TALLOC_ABORT("Bad talloc magic value - unknown value"); 
@@ -180,7 +183,7 @@ void *_talloc(const void *context, size_t size)
        if (tc == NULL) return NULL;
 
        tc->size = size;
-       tc->magic = TALLOC_MAGIC;
+       tc->u.magic = TALLOC_MAGIC;
        tc->destructor = NULL;
        tc->child = NULL;
        tc->name = NULL;
@@ -559,7 +562,7 @@ int talloc_free(void *ptr)
                if (tc->next) tc->next->prev = tc->prev;
        }
 
-       tc->magic = TALLOC_MAGIC_FREE;
+       tc->u.magic = TALLOC_MAGIC_FREE;
 
        free(tc);
        return 0;
@@ -599,7 +602,7 @@ 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;
+       tc->u.magic = TALLOC_MAGIC_FREE;
 
 #if ALWAYS_REALLOC
        new_ptr = malloc(size + sizeof(*tc));
@@ -611,12 +614,12 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
        new_ptr = realloc(tc, size + sizeof(*tc));
 #endif
        if (!new_ptr) { 
-               tc->magic = TALLOC_MAGIC; 
+               tc->u.magic = TALLOC_MAGIC; 
                return NULL; 
        }
 
        tc = new_ptr;
-       tc->magic = TALLOC_MAGIC;
+       tc->u.magic = TALLOC_MAGIC;
        if (tc->parent) {
                tc->parent->child = new_ptr;
        }