@@ -283,20 +283,24 @@ test_atomic_funcs(PyObject *self, PyObject *Py_UNUSED(args))
283283static int
284284check_edit_cost (const char * a , const char * b , Py_ssize_t expected )
285285{
286- PyObject * a_obj = PyUnicode_FromString (a );
286+ int ret = -1 ;
287+ PyObject * a_obj = NULL ;
288+ PyObject * b_obj = NULL ;
289+
290+ a_obj = PyUnicode_FromString (a );
287291 if (a_obj == NULL ) {
288- return -1 ;
292+ goto exit ;
289293 }
290- PyObject * b_obj = PyUnicode_FromString (b );
294+ b_obj = PyUnicode_FromString (b );
291295 if (a_obj == NULL ) {
292- return -1 ;
296+ goto exit ;
293297 }
294298 Py_ssize_t result = _Py_UTF8_Edit_Cost (a_obj , b_obj , -1 );
295299 if (result != expected ) {
296300 PyErr_Format (PyExc_AssertionError ,
297301 "Edit cost from '%s' to '%s' returns %zd, expected %zd" ,
298302 a , b , result , expected );
299- return -1 ;
303+ goto exit ;
300304 }
301305 // Check that smaller max_edits thresholds are exceeded.
302306 Py_ssize_t max_edits = result ;
@@ -308,7 +312,7 @@ check_edit_cost(const char *a, const char *b, Py_ssize_t expected)
308312 "Edit cost from '%s' to '%s' (threshold %zd) "
309313 "returns %zd, expected greater than %zd" ,
310314 a , b , max_edits , result2 , max_edits );
311- return -1 ;
315+ goto exit ;
312316 }
313317 }
314318 // Check that bigger max_edits thresholds don't change anything
@@ -318,9 +322,13 @@ check_edit_cost(const char *a, const char *b, Py_ssize_t expected)
318322 "Edit cost from '%s' to '%s' (threshold %zd) "
319323 "returns %zd, expected %zd" ,
320324 a , b , result * 2 , result3 , result );
321- return -1 ;
325+ goto exit ;
322326 }
323- return 0 ;
327+ ret = 0 ;
328+ exit :
329+ Py_XDECREF (a_obj );
330+ Py_XDECREF (b_obj );
331+ return ret ;
324332}
325333
326334static PyObject *
0 commit comments