diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 0d95d2b6f76eceb..2a22895f40ee14d 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2731,10 +2731,11 @@ PyCData_reduce(PyObject *myself, PyObject *args) "ctypes objects containing pointers cannot be pickled"); return NULL; } - return Py_BuildValue("O(O(NN))", - _unpickle, - Py_TYPE(myself), - PyObject_GetAttrString(myself, "__dict__"), + PyObject *dict = PyObject_GetAttrString(myself, "__dict__"); + if (dict == NULL) { + return NULL; + } + return Py_BuildValue("O(O(NN))", _unpickle, Py_TYPE(myself), dict, PyBytes_FromStringAndSize(self->b_ptr, self->b_size)); }