From ff0ae9b29d7707d63d6f0ad4a64b578021783693 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 3 Jun 2022 20:49:17 -0700 Subject: [PATCH] dynamic_cast before destructor Call to the destructor ends lifetime of the object, including vptr used by dynamic_cast. --- src/object/class.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/object/class.cpp b/src/object/class.cpp index 8bb462ce..e03d4e00 100644 --- a/src/object/class.cpp +++ b/src/object/class.cpp @@ -333,8 +333,9 @@ namespace objects for (instance_holder* p = kill_me->objects, *next; p != 0; p = next) { next = p->next(); + void* q = dynamic_cast(p); p->~instance_holder(); - instance_holder::deallocate(inst, dynamic_cast(p)); + instance_holder::deallocate(inst, q); } // Python 2.2.1 won't add weak references automatically when