# HG changeset patch # User Tassilo Philipp # Date 1716567389 -7200 # Node ID 7a61dd082341d5bfe841cbed0dcc49f0bb1117f8 # Parent 75a4082f0fcef33b636331e3902815e3d8066889 pydc: - fix double free triggered by capsule destructor, when freeing pydc and callback objects, manually diff -r 75a4082f0fce -r 7a61dd082341 python/pydc/pydc.c --- a/python/pydc/pydc.c Sun May 19 15:45:13 2024 +0200 +++ b/python/pydc/pydc.c Fri May 24 18:16:29 2024 +0200 @@ -28,7 +28,7 @@ # define USE_CAPSULE_API # define DcPyCObject_FromVoidPtr(ptr, dtor) PyCapsule_New((ptr), NULL, (dtor)) // !new ref! # define DcPyCObject_AsVoidPtr(ppobj) PyCapsule_GetPointer((ppobj), NULL) -# define DcPyCObject_SetVoidPtr(ppobj, ptr) //@@@ unsure what to do, cannot/shouldn't call this with a null pointer as this wants to call the dtor, so not doing anything: PyCapsule_SetPointer((ppobj), (ptr)) // this might need to call the dtor to behave like PyCObject_SetVoidPtr? +# define DcPyCObject_SetVoidPtr(ppobj, ptr) PyCapsule_SetDestructor((ppobj), NULL) // just remove the dtor (this allows for free_callback) to be called, explicitly # define DcPyCObject_Check(ppobj) PyCapsule_CheckExact((ppobj)) #endif @@ -764,7 +764,7 @@ DcPyCObject_SetVoidPtr(pcobj, NULL); //don't think I need to release it, as the pyobj is not equivalent to the held handle - //Py_XDECREF(pcobj); // release ref from pydc_load() + //Py_XDECREF(pcobj); // release ref from pydc_new_callback() Py_RETURN_NONE; }