talloc: Slightly simplify talloc_unlink
authorVolker Lendecke <vl@samba.org>
Mon, 2 Jan 2012 13:56:04 +0000 (14:56 +0100)
committerVolker Lendecke <vlendec@samba.org>
Mon, 2 Jan 2012 18:07:23 +0000 (19:07 +0100)
Nested if's are hard to understand to me.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Mon Jan  2 19:07:23 CET 2012 on sn-devel-104

lib/talloc/talloc.c

index 8c71cc74ca8205e76193587a29b59f0282a67bc3..38e6f21854a643559a4cf653ce8f7125f0984651 100644 (file)
@@ -1043,7 +1043,7 @@ static inline int talloc_unreference(const void *context, const void *ptr)
 */
 _PUBLIC_ int talloc_unlink(const void *context, void *ptr)
 {
-       struct talloc_chunk *tc_p, *new_p;
+       struct talloc_chunk *tc_p, *new_p, *tc_c;
        void *new_parent;
 
        if (ptr == NULL) {
@@ -1058,14 +1058,13 @@ _PUBLIC_ int talloc_unlink(const void *context, void *ptr)
                return 0;
        }
 
-       if (context == NULL) {
-               if (talloc_parent_chunk(ptr) != NULL) {
-                       return -1;
-               }
+       if (context != NULL) {
+               tc_c = talloc_chunk_from_ptr(context);
        } else {
-               if (talloc_chunk_from_ptr(context) != talloc_parent_chunk(ptr)) {
-                       return -1;
-               }
+               tc_c = NULL;
+       }
+       if (tc_c != talloc_parent_chunk(ptr)) {
+               return -1;
        }
        
        tc_p = talloc_chunk_from_ptr(ptr);