libxl: ao: Count the nested progeny of an ao
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 20 Dec 2013 15:58:35 +0000 (15:58 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 26 Jun 2015 15:53:50 +0000 (16:53 +0100)
This will detect any "escaped" nested aos.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl_event.c
tools/libxl/libxl_internal.h

index 47d65a3742450a1d5648e8df8ee0db58770457b2..96efb33e2675b655fb2dec5efd6a7da5d967b7f7 100644 (file)
@@ -1765,6 +1765,7 @@ void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc)
     assert(ao->magic == LIBXL__AO_MAGIC);
     assert(!ao->complete);
     assert(!ao->nested_root);
+    assert(!ao->nested_progeny);
     ao->complete = 1;
     ao->rc = rc;
 
@@ -1975,6 +1976,8 @@ _hidden libxl__ao *libxl__nested_ao_create(libxl__ao *parent)
     child = libxl__zalloc(&ctx->nogc_gc, sizeof(*child));
     child->magic = LIBXL__AO_MAGIC;
     child->nested_root = root;
+    assert(root->nested_progeny < INT_MAX);
+    root->nested_progeny++;
     LIBXL_INIT_GC(child->gc, ctx);
     libxl__gc *gc = &child->gc;
 
@@ -1985,7 +1988,10 @@ _hidden libxl__ao *libxl__nested_ao_create(libxl__ao *parent)
 _hidden void libxl__nested_ao_free(libxl__ao *child)
 {
     assert(child->magic == LIBXL__AO_MAGIC);
-    assert(child->nested_root);
+    libxl__ao *root = child->nested_root;
+    assert(root);
+    assert(root->nested_progeny > 0);
+    root->nested_progeny--;
     libxl_ctx *ctx = libxl__gc_owner(&child->gc);
     libxl__ao__destroy(ctx, child);
 }
index 9e5758517ac91f0f2d4d9744539757dd51d4666d..79cdec14109bbc26749dea8a40293d6f7312e3a2 100644 (file)
@@ -470,6 +470,7 @@ struct libxl__ao {
     uint32_t magic;
     unsigned constructing:1, in_initiator:1, complete:1, notified:1;
     libxl__ao *nested_root;
+    int nested_progeny;
     int progress_reports_outstanding;
     int rc;
     libxl__gc gc;