@@ -176,7 +176,11 @@ BaseException_repr(PyBaseExceptionObject *self)
176
176
}
177
177
key = PyTuple_GET_ITEM (item , 0 );
178
178
value = PyTuple_GET_ITEM (item , 1 );
179
- PyTuple_SET_ITEM (seq , i , PyUnicode_FromFormat ("%S=%R" , key , value ));
179
+ repr = PyUnicode_FromFormat ("%S=%R" , key , value );
180
+ if (repr == NULL ) {
181
+ goto fail ;
182
+ }
183
+ PyTuple_SET_ITEM (seq , i , repr );
180
184
i ++ ;
181
185
Py_DECREF (item );
182
186
}
@@ -221,36 +225,41 @@ BaseException_reduce(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored))
221
225
PyObject * functools ;
222
226
PyObject * partial ;
223
227
PyObject * constructor ;
224
- PyObject * args ;
225
228
PyObject * result ;
226
229
PyObject * * newargs ;
227
230
228
231
_Py_IDENTIFIER (partial );
229
232
functools = PyImport_ImportModule ("functools" );
230
- if (! functools )
233
+ if (functools == NULL ) {
231
234
return NULL ;
235
+ }
232
236
partial = _PyObject_GetAttrId (functools , & PyId_partial );
233
237
Py_DECREF (functools );
234
- if (! partial )
238
+ if (partial == NULL ) {
235
239
return NULL ;
240
+ }
236
241
237
242
Py_ssize_t len = 1 ;
238
243
if (PyTuple_Check (self -> args )) {
239
244
len += PyTuple_GET_SIZE (self -> args );
240
245
}
241
- newargs = PyMem_RawMalloc (len * sizeof (PyObject * ));
246
+ newargs = PyMem_New (PyObject * , len );
247
+ if (newargs == NULL ) {
248
+ PyErr_NoMemory ();
249
+ return NULL ;
250
+ }
242
251
newargs [0 ] = (PyObject * )Py_TYPE (self );
243
252
244
253
for (Py_ssize_t i = 1 ; i < len ; i ++ ) {
245
254
newargs [i ] = PyTuple_GetItem (self -> args , i - 1 );
246
255
}
247
256
constructor = _PyObject_FastCallDict (partial , newargs , len , self -> kwargs );
248
- PyMem_RawFree (newargs );
257
+ PyMem_Free (newargs );
249
258
250
259
Py_DECREF (partial );
251
260
252
- args = PyTuple_New (0 );
253
- if (! args ) {
261
+ PyObject * args = PyTuple_New (0 );
262
+ if (args == NULL ) {
254
263
return NULL ;
255
264
}
256
265
if (self -> args && self -> dict ){
0 commit comments