comparison python/pydc/pydc.c @ 66:7a61dd082341 default tip

pydc: - fix double free triggered by capsule destructor, when freeing pydc and callback objects, manually
author Tassilo Philipp
date Fri, 24 May 2024 18:16:29 +0200
parents 75a4082f0fce
children
comparison
equal deleted inserted replaced
65:75a4082f0fce 66:7a61dd082341
26 # define DcPyCObject_Check(ppobj) PyCObject_Check((ppobj)) 26 # define DcPyCObject_Check(ppobj) PyCObject_Check((ppobj))
27 #else 27 #else
28 # define USE_CAPSULE_API 28 # define USE_CAPSULE_API
29 # define DcPyCObject_FromVoidPtr(ptr, dtor) PyCapsule_New((ptr), NULL, (dtor)) // !new ref! 29 # define DcPyCObject_FromVoidPtr(ptr, dtor) PyCapsule_New((ptr), NULL, (dtor)) // !new ref!
30 # define DcPyCObject_AsVoidPtr(ppobj) PyCapsule_GetPointer((ppobj), NULL) 30 # define DcPyCObject_AsVoidPtr(ppobj) PyCapsule_GetPointer((ppobj), NULL)
31 # 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? 31 # define DcPyCObject_SetVoidPtr(ppobj, ptr) PyCapsule_SetDestructor((ppobj), NULL) // just remove the dtor (this allows for free_callback) to be called, explicitly
32 # define DcPyCObject_Check(ppobj) PyCapsule_CheckExact((ppobj)) 32 # define DcPyCObject_Check(ppobj) PyCapsule_CheckExact((ppobj))
33 #endif 33 #endif
34 34
35 #if(PY_VERSION_HEX >= 0x03030000) 35 #if(PY_VERSION_HEX >= 0x03030000)
36 # define PYUNICODE_CACHES_UTF8 36 # define PYUNICODE_CACHES_UTF8
762 762
763 dcbFreeCallback(cb); 763 dcbFreeCallback(cb);
764 DcPyCObject_SetVoidPtr(pcobj, NULL); 764 DcPyCObject_SetVoidPtr(pcobj, NULL);
765 765
766 //don't think I need to release it, as the pyobj is not equivalent to the held handle 766 //don't think I need to release it, as the pyobj is not equivalent to the held handle
767 //Py_XDECREF(pcobj); // release ref from pydc_load() 767 //Py_XDECREF(pcobj); // release ref from pydc_new_callback()
768 768
769 Py_RETURN_NONE; 769 Py_RETURN_NONE;
770 } 770 }
771 771
772 772