@@ -225,8 +225,10 @@ _PyErr_SetString(PyThreadState *tstate, PyObject *exception,
225
225
const char * string )
226
226
{
227
227
PyObject * value = PyUnicode_FromString (string );
228
- _PyErr_SetObject (tstate , exception , value );
229
- Py_XDECREF (value );
228
+ if (value != NULL ) {
229
+ _PyErr_SetObject (tstate , exception , value );
230
+ Py_DECREF (value );
231
+ }
230
232
}
231
233
232
234
void
@@ -852,7 +854,13 @@ PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, P
852
854
PyObject *
853
855
PyErr_SetFromErrnoWithFilename (PyObject * exc , const char * filename )
854
856
{
855
- PyObject * name = filename ? PyUnicode_DecodeFSDefault (filename ) : NULL ;
857
+ PyObject * name = NULL ;
858
+ if (filename ) {
859
+ name = PyUnicode_DecodeFSDefault (filename );
860
+ if (name == NULL ) {
861
+ return NULL ;
862
+ }
863
+ }
856
864
PyObject * result = PyErr_SetFromErrnoWithFilenameObjects (exc , name , NULL );
857
865
Py_XDECREF (name );
858
866
return result ;
@@ -949,7 +957,13 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilename(
949
957
int ierr ,
950
958
const char * filename )
951
959
{
952
- PyObject * name = filename ? PyUnicode_DecodeFSDefault (filename ) : NULL ;
960
+ PyObject * name = NULL ;
961
+ if (filename ) {
962
+ name = PyUnicode_DecodeFSDefault (filename );
963
+ if (name == NULL ) {
964
+ return NULL ;
965
+ }
966
+ }
953
967
PyObject * ret = PyErr_SetExcFromWindowsErrWithFilenameObjects (exc ,
954
968
ierr ,
955
969
name ,
@@ -973,7 +987,13 @@ PyObject *PyErr_SetFromWindowsErrWithFilename(
973
987
int ierr ,
974
988
const char * filename )
975
989
{
976
- PyObject * name = filename ? PyUnicode_DecodeFSDefault (filename ) : NULL ;
990
+ PyObject * name = NULL ;
991
+ if (filename ) {
992
+ name = PyUnicode_DecodeFSDefault (filename );
993
+ if (name == NULL ) {
994
+ return NULL ;
995
+ }
996
+ }
977
997
PyObject * result = PyErr_SetExcFromWindowsErrWithFilenameObjects (
978
998
PyExc_OSError ,
979
999
ierr , name , NULL );
@@ -1076,9 +1096,10 @@ _PyErr_FormatV(PyThreadState *tstate, PyObject *exception,
1076
1096
_PyErr_Clear (tstate );
1077
1097
1078
1098
string = PyUnicode_FromFormatV (format , vargs );
1079
-
1080
- _PyErr_SetObject (tstate , exception , string );
1081
- Py_XDECREF (string );
1099
+ if (string != NULL ) {
1100
+ _PyErr_SetObject (tstate , exception , string );
1101
+ Py_DECREF (string );
1102
+ }
1082
1103
return NULL ;
1083
1104
}
1084
1105
0 commit comments