mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 08:44:19 -04:00
py_panda: fix leak of reference counted class with inaccessible dtor
If a class inherits from ReferenceCount, it can be destructed by downcasting to ReferenceCount, so it should not be an obstacle to properly clean it up when such a class is returned from C++. This issue comes up when a CycleData is returned via MemoryUsagePointers, which is not exposed so is wrapped as NodeReferenceCount instead, which has a protected destructor.
This commit is contained in:
parent
b0bbc66f06
commit
0367c73026
@ -158,6 +158,16 @@ static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
|
||||
Py_TYPE(self)->tp_free(self);\
|
||||
}
|
||||
|
||||
#define Define_Dtool_FreeInstanceRef_Private(CLASS_NAME,CNAME)\
|
||||
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
|
||||
if (DtoolInstance_VOID_PTR(self) != nullptr) {\
|
||||
if (((Dtool_PyInstDef *)self)->_memory_rules) {\
|
||||
unref_delete((ReferenceCount *)(CNAME *)DtoolInstance_VOID_PTR(self));\
|
||||
}\
|
||||
}\
|
||||
Py_TYPE(self)->tp_free(self);\
|
||||
}
|
||||
|
||||
#define Define_Dtool_Simple_FreeInstance(CLASS_NAME, CNAME)\
|
||||
static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
|
||||
((Dtool_InstDef_##CLASS_NAME *)self)->_value.~##CLASS_NAME();\
|
||||
@ -292,7 +302,7 @@ Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME)
|
||||
#define Define_Module_ClassRef_Private(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\
|
||||
Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\
|
||||
Define_Dtool_new(CLASS_NAME,CNAME)\
|
||||
Define_Dtool_FreeInstance_Private(CLASS_NAME,CNAME)\
|
||||
Define_Dtool_FreeInstanceRef_Private(CLASS_NAME,CNAME)\
|
||||
Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME)
|
||||
|
||||
#define Define_Module_ClassRef(MODULE_NAME,CLASS_NAME,CNAME,PUBLIC_NAME)\
|
||||
|
Loading…
x
Reference in New Issue
Block a user