From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vns7F-0005kj-BL for qemu-devel@nongnu.org; Tue, 03 Dec 2013 10:42:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vns79-0000qW-QE for qemu-devel@nongnu.org; Tue, 03 Dec 2013 10:42:25 -0500 Received: from mail-qa0-x230.google.com ([2607:f8b0:400d:c00::230]:33171) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vns79-0000qQ-M2 for qemu-devel@nongnu.org; Tue, 03 Dec 2013 10:42:19 -0500 Received: by mail-qa0-f48.google.com with SMTP id w5so5757064qac.0 for ; Tue, 03 Dec 2013 07:42:19 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 3 Dec 2013 16:42:00 +0100 Message-Id: <1386085320-12965-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1386085320-12965-1-git-send-email-pbonzini@redhat.com> References: <1386085320-12965-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 2/2] 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: peter.crosthwaite@xilinx.com, hpoussin@reactos.org, afaerber@suse.de 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 --- qom/object.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qom/object.c b/qom/object.c index 3a43186..1dee9f0 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 = false; static void type_table_add(TypeImpl *ti) { + assert(!enumerating); 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 = true; g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data); + enumerating = false; } int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque), -- 1.8.4.2