From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqgwR-0001Z2-BB for qemu-devel@nongnu.org; Wed, 11 Dec 2013 05:23:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VqgwJ-0001F2-Nd for qemu-devel@nongnu.org; Wed, 11 Dec 2013 05:22:55 -0500 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:35924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqgwJ-0001ES-12 for qemu-devel@nongnu.org; Wed, 11 Dec 2013 05:22:47 -0500 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 11 Dec 2013 20:22:42 +1000 From: Alexey Kardashevskiy Date: Wed, 11 Dec 2013 21:22:15 +1100 Message-Id: <1386757341-12154-3-git-send-email-aik@ozlabs.ru> In-Reply-To: <1386757341-12154-1-git-send-email-aik@ozlabs.ru> References: <1386757341-12154-1-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v4 2/8] qom: detect bad reentrance during object_class_foreach List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aik@ozlabs.ru, qemu-ppc@nongnu.org, =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Alexander Graf , Paolo Bonzini From: Hervé Poussineau We should not modify the type hash table while it is being iterated on. Assert that it does not happen. Signed-off-by: Hervé Poussineau Signed-off-by: Paolo Bonzini Signed-off-by: Alexey Kardashevskiy --- Changes: v4: * rename: @enumerating -> @enumerating_types * @enumerating_types is static and does not require initialization to "false" --- qom/object.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qom/object.c b/qom/object.c index 3a43186..937af00 100644 --- a/qom/object.c +++ b/qom/object.c @@ -78,8 +78,10 @@ static GHashTable *type_table_get(void) return type_table; } +static bool enumerating_types; static void type_table_add(TypeImpl *ti) { + assert(!enumerating_types); g_hash_table_insert(type_table_get(), (void *)ti->name, ti); } @@ -666,7 +668,9 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque), { OCFData data = { fn, implements_type, include_abstract, opaque }; + enumerating_types = true; g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data); + enumerating_types = false; } int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque), -- 1.8.4.rc4