8000 More error paths · python/cpython@e784da1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e784da1

Browse files
committed
More error paths
1 parent fd0f7b4 commit e784da1

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

Objects/typevarobject.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ typevar_alloc(const char *name, PyObject *bound, PyObject *evaluate_bound,
286286

287287
char *owned_name = strdup(name);
288288
if (owned_name == NULL) {
289+
PyErr_NoMemory();
289290
return NULL;
290291
}
291292

@@ -307,7 +308,7 @@ typevar_alloc(const char *name, PyObject *bound, PyObject *evaluate_bound,
307308
tv->covariant = covariant;
308309
tv->contravariant = contravariant;
309310
tv->infer_variance = infer_variance;
310-
PyObject_GC_Track(tv);
311+
_PyObject_GC_TRACK(tv);
311312

312313
if (module != NULL) {
313314
if (PyObject_SetAttrString((PyObject *)tv, "__module__", module) < 0) {
@@ -813,27 +814,29 @@ static paramspecobject *
813814
paramspec_alloc(const char *name, PyObject *bound, bool covariant,
814815
bool contravariant, bool infer_variance, PyObject *module)
815816
{
817+
char *owned_name = strdup(name);
818+
if (owned_name == NULL) {
819+
PyErr_NoMemory();
820+
return NULL;
821+
}
816822
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspec_type;
817823
paramspecobject *ps = PyObject_GC_New(paramspecobject, tp);
818824
if (ps == NULL) {
825+
free((void *)owned_name);
819826
return NULL;
820827
}
821-
ps->name = strdup(name);
822-
if (ps->name == NULL) {
823-
Py_DECREF(ps);
824-
return NULL;
825-
}
828+
ps->name = owned_name;
826829
ps->bound = Py_XNewRef(bound);
827830
ps->covariant = covariant;
828831
ps->contravariant = contravariant;
829832
ps->infer_variance = infer_variance;
833+
_PyObject_GC_TRACK(ps);
830834
if (module != NULL) {
831835
if (PyObject_SetAttrString((PyObject *)ps, "__module__", module) < 0) {
832836
Py_DECREF(ps);
833837
return NULL;
834838
}
835839
}
836-
_PyObject_GC_TRACK(ps);
837840
return ps;
838841
}
839842

@@ -1071,23 +1074,25 @@ static PyMemberDef typevartuple_members[] = {
10711074
static typevartupleobject *
10721075
typevartuple_alloc(const char *name, PyObject *module)
10731076
{
1077+
char *owned_name = strdup(name);
1078+
if (owned_name == NULL) {
1079+
PyErr_NoMemory();
1080+
return NULL;
1081+
}
10741082
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevartuple_type;
10751083
typevartupleobject *tvt = PyObject_GC_New(typevartupleobject, tp);
10761084
if (tvt == NULL) {
1085+
free(owned_name);
10771086
return NULL;
10781087
}
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);
10841090
if (module != NULL) {
10851091
if (PyObject_SetAttrString((PyObject *)tvt, "__module__", module) < 0) {
10861092
Py_DECREF(tvt);
10871093
return NULL;
10881094
}
10891095
}
1090-
_PyObject_GC_TRACK(tvt);
10911096
return tvt;
10921097
}
10931098

@@ -1421,16 +1426,18 @@ static PyGetSetDef typealias_getset[] = {
14211426
static typealiasobject *
14221427
typealias_alloc(const char *name, PyObject *type_params, PyObject *compute_value)
14231428
{
1429+
char *owned_name = strdup(name);
1430+
if (owned_name == NULL) {
1431+
PyErr_NoMemory();
1432+
return NULL;
1433+
}
14241434
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typealias_type;
14251435
typealiasobject *ta = PyObject_GC_New(typealiasobject, tp);
14261436
if (ta == NULL) {
1437+
free(owned_name);
14271438
return NULL;
14281439
}
1429-
ta->name = strdup(name);
1430-
if (ta->name == NULL) {
1431-
Py_DECREF(ta);
1432-
return NULL;
1433-
}
1440+
ta->name = owned_name;
14341441
ta->type_params = Py_IsNone(type_params) ? NULL : Py_XNewRef(type_params);
14351442
ta->compute_value = Py_NewRef(compute_value);
14361443
ta->value = NULL;

0 commit comments

Comments
 (0)
0