talloc: Remove talloc_abort_magic()
authorAndrew Bartlett <abartlet@samba.org>
Mon, 8 Jan 2018 04:29:19 +0000 (17:29 +1300)
committerStefan Metzmacher <metze@samba.org>
Fri, 12 Jan 2018 21:42:21 +0000 (22:42 +0100)
The check required for talloc_abort_magic() prevents the 'access after free error'
from being printed.

It is also no longer possible to determine the difference between invalid memory
and a talloc version mismatch as the magic is now random on many platforms.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13210

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
lib/talloc/talloc.c

index 7721fa4a9c6d7d59c3f85b82eaeeae2b3f09d4b7..3569ba759290871f16df0dd64be3165f50a6ddd5 100644 (file)
@@ -429,11 +429,6 @@ static void talloc_abort(const char *reason)
        talloc_abort_fn(reason);
 }
 
-static void talloc_abort_magic(unsigned magic)
-{
-       talloc_abort("Bad talloc magic value - wrong talloc version used/mixed");
-}
-
 static void talloc_abort_access_after_free(void)
 {
        talloc_abort("Bad talloc magic value - access after free");
@@ -450,19 +445,14 @@ static inline struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr)
        const char *pp = (const char *)ptr;
        struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE);
        if (unlikely((tc->flags & (TALLOC_FLAG_FREE | ~TALLOC_FLAG_MASK)) != talloc_magic)) {
-               if ((tc->flags & (~TALLOC_FLAG_MASK)) == talloc_magic) {
-                       talloc_abort_magic(tc->flags & (~TALLOC_FLAG_MASK));
-                       return NULL;
-               }
-
-               if (tc->flags & TALLOC_FLAG_FREE) {
-                       talloc_log("talloc: access after free error - first free may be at %s\n", tc->name);
-                       talloc_abort_access_after_free();
-                       return NULL;
-               } else {
+               if ((tc->flags & (~TALLOC_FLAG_MASK)) != talloc_magic) {
                        talloc_abort_unknown_value();
                        return NULL;
                }
+
+               talloc_log("talloc: access after free error - first free may be at %s\n", tc->name);
+               talloc_abort_access_after_free();
+               return NULL;
        }
        return tc;
 }