@@ -404,7 +404,7 @@ builtin_compile(PyObject *self, PyObject *args)
404404 int dont_inherit = 0 ;
405405 int supplied_flags = 0 ;
406406 PyCompilerFlags cf ;
407- PyObject * result , * cmd , * tmp = NULL ;
407+ PyObject * result = NULL , * cmd , * tmp = NULL ;
408408 int length ;
409409
410410 if (!PyArg_ParseTuple (args , "Oss|ii:compile" , & cmd , & filename ,
@@ -427,7 +427,7 @@ builtin_compile(PyObject *self, PyObject *args)
427427 if ((size_t )length != strlen (str )) {
428428 PyErr_SetString (PyExc_TypeError ,
429429 "compile() expected string without null bytes" );
430- return NULL ;
430+ goto cleanup ;
431431 }
432432
433433 if (strcmp (startstr , "exec" ) == 0 )
@@ -439,22 +439,23 @@ builtin_compile(PyObject *self, PyObject *args)
439439 else {
440440 PyErr_SetString (PyExc_ValueError ,
441441 "compile() arg 3 must be 'exec' or 'eval' or 'single'" );
442- return NULL ;
442+ goto cleanup ;
443443 }
444444
445445 if (supplied_flags &
446446 ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT ))
447447 {
448448 PyErr_SetString (PyExc_ValueError ,
449449 "compile(): unrecognised flags" );
450- return NULL ;
450+ goto cleanup ;
451451 }
452452 /* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */
453453
454454 if (!dont_inherit ) {
455455 PyEval_MergeCompilerFlags (& cf );
456456 }
457457 result = Py_CompileStringFlags (str , filename , start , & cf );
458+ cleanup :
458459 Py_XDECREF (tmp );
459460 return result ;
460461}
@@ -580,8 +581,10 @@ builtin_eval(PyObject *self, PyObject *args)
580581 cf .cf_flags |= PyCF_SOURCE_IS_UTF8 ;
581582 }
582583#endif
583- if (PyString_AsStringAndSize (cmd , & str , NULL ))
584+ if (PyString_AsStringAndSize (cmd , & str , NULL )) {
585+ Py_XDECREF (tmp );
584586 return NULL ;
587+ }
585588 while (* str == ' ' || * str == '\t' )
586589 str ++ ;
587590
0 commit comments