@@ -286,6 +286,7 @@ typevar_alloc(const char *name, PyObject *bound, PyObject *evaluate_bound,
286
286
287
287
char * owned_name = strdup (name );
288
288
if (owned_name == NULL ) {
289
+ PyErr_NoMemory ();
289
290
return NULL ;
290
291
}
291
292
@@ -307,7 +308,7 @@ typevar_alloc(const char *name, PyObject *bound, PyObject *evaluate_bound,
307
308
tv -> covariant = covariant ;
308
309
tv -> contravariant = contravariant ;
309
310
tv -> infer_variance = infer_variance ;
310
- PyObject_GC_Track (tv );
311
+ _PyObject_GC_TRACK (tv );
311
312
312
313
if (module != NULL ) {
313
314
if (PyObject_SetAttrString ((PyObject * )tv , "__module__" , module ) < 0 ) {
@@ -813,27 +814,29 @@ static paramspecobject *
813
814
paramspec_alloc (const char * name , PyObject * bound , bool covariant ,
814
815
bool contravariant , bool infer_variance , PyObject * module )
815
816
{
817
+ char * owned_name = strdup (name );
818
+ if (owned_name == NULL ) {
819
+ PyErr_NoMemory ();
820
+ return NULL ;
821
+ }
816
822
PyTypeObject * tp = PyInterpreterState_Get ()-> cached_objects .paramspec_type ;
817
823
paramspecobject * ps = PyObject_GC_New (paramspecobject , tp );
818
824
if (ps == NULL ) {
825
+ free ((void * )owned_name );
819
826
return NULL ;
820
827
}
821
- ps -> name = strdup (name );
822
- if (ps -> name == NULL ) {
823
- Py_DECREF (ps );
824
- return NULL ;
825
- }
828
+ ps -> name = owned_name ;
826
829
ps -> bound = Py_XNewRef (bound );
827
830
ps -> covariant = covariant ;
828
831
ps -> contravariant = contravariant ;
829
832
ps -> infer_variance = infer_variance ;
833
+ _PyObject_GC_TRACK (ps );
830
834
if (module != NULL ) {
831
835
if (PyObject_SetAttrString ((PyObject * )ps , "__module__" , module ) < 0 ) {
832
836
Py_DECREF (ps );
833
837
return NULL ;
834
838
}
835
839
}
836
- _PyObject_GC_TRACK (ps );
837
840
return ps ;
838
841
}
839
842
@@ -1071,23 +1074,25 @@ static PyMemberDef typevartuple_members[] = {
1071
1074
static typevartupleobject *
1072
1075
typevartuple_alloc (const char * name , PyObject * module )
1073
1076
{
1077
+ char * owned_name = strdup (name );
1078
+ if (owned_name == NULL ) {
1079
+ PyErr_NoMemory ();
1080
+ return NULL ;
1081
+ }
1074
1082
PyTypeObject * tp = PyInterpreterState_Get ()-> cached_objects .typevartuple_type ;
1075
1083
typevartupleobject * tvt = PyObject_GC_New (typevartupleobject , tp );
1076
1084
if (tvt == NULL ) {
1085
+ free (owned_name );
1077
1086
return NULL ;
1078
1087
}
1079
- tvt -> name = strdup (name );
1080
- if (tvt -> name == NULL ) {
1081
- Py_DECREF (tvt );
1082
- return NULL ;
1083
- }
8000
1088
+ tvt -> name = owned_name ;
1089
+ _PyObject_GC_TRACK (tvt );
1084
1090
if (module != NULL ) {
1085
1091
if (PyObject_SetAttrString ((PyObject * )tvt , "__module__" , module ) < 0 ) {
1086
1092
Py_DECREF (tvt );
1087
1093
return NULL ;
1088
1094
}
1089
1095
}
1090
- _PyObject_GC_TRACK (tvt );
1091
1096
return tvt ;
1092
1097
}
1093
1098
@@ -1421,16 +1426,18 @@ static PyGetSetDef typealias_getset[] = {
1421
1426
static typealiasobject *
1422
1427
typealias_alloc (const char * name , PyObject * type_params , PyObject * compute_value )
1423
1428
{
1429
+ char * owned_name = strdup (name );
1430
+ if (owned_name == NULL ) {
1431
+ PyErr_NoMemory ();
1432
+ return NULL ;
1433
+ }
1424
1434
PyTypeObject * tp = PyInterpreterState_Get ()-> cached_objects .typealias_type ;
1425
1435
typealiasobject * ta = PyObject_GC_New (typealiasobject , tp );
1426
1436
if (ta == NULL ) {
1437
+ free (owned_name );
1427
1438
return NULL ;
1428
1439
}
1429
- ta -> name = strdup (name );
1430
- if (ta -> name == NULL ) {
1431
- Py_DECREF (ta );
1432
- return NULL ;
1433
- }
1440
+ ta -> name = owned_name ;
1434
1441
ta -> type_params = Py_IsNone (type_params ) ? NULL : Py_XNewRef (type_params );
1435
1442
ta -> compute_value = Py_NewRef (compute_value );
1436
1443
ta -> value = NULL ;
0 commit comments