Skip to content

Commit 2b6c12a

Browse files
authored
Decref the module explicitly on exec error
1 parent 6a83ad7 commit 2b6c12a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Modules/_datetimemodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7173,8 +7173,6 @@ create_timezone_from_delta(int days, int sec, int ms, int normalize)
71737173
static int
71747174
init_state(datetime_state *st, PyObject *module, PyObject *old_module)
71757175
{
7176-
st->module = Py_NewRef(module);
7177-
71787176
/* Each module gets its own heap types. */
71797177
#define ADD_TYPE(FIELD, SPEC, BASE) \
71807178
do { \
@@ -7253,7 +7251,6 @@ init_state(datetime_state *st, PyObject *module, PyObject *old_module)
72537251
static int
72547252
traverse_state(datetime_state *st, visitproc visit, void *arg)
72557253
{
7256-
Py_VISIT(st->module);
72577254
Py_VISIT(st->isocalendar_date_type);
72587255

72597256
return 0;
@@ -7262,7 +7259,6 @@ traverse_state(datetime_state *st, visitproc visit, void *arg)
72627259
static int
72637260
clear_state(datetime_state *st)
72647261
{
7265-
Py_CLEAR(st->module); /* Invalidate first */
72667262
Py_CLEAR(st->isocalendar_date_type);
72677263
Py_CLEAR(st->us_per_ms);
72687264
Py_CLEAR(st->us_per_second);
@@ -7339,6 +7335,7 @@ _datetime_exec(PyObject *module)
73397335
}
73407336
}
73417337

7338+
st->module = Py_NewRef(module);
73427339
if (init_state(st, module, old_module) < 0) {
73437340
goto error;
73447341
}
@@ -7453,6 +7450,7 @@ _datetime_exec(PyObject *module)
74537450
goto finally;
74547451

74557452
error:
7453+
Py_CLEAR(st->module);
74567454
clear_state(st);
74577455

74587456
finally:
@@ -7471,6 +7469,7 @@ static int
74717469
module_traverse(PyObject *mod, visitproc visit, void *arg)
74727470
{
74737471
datetime_state *st = get_module_state(mod);
7472+
Py_VISIT(st->module);
74747473
traverse_state(st, visit, arg);
74757474
return 0;
74767475
}
@@ -7479,6 +7478,7 @@ static int
74797478
module_clear(PyObject *mod)
74807479
{
74817480
datetime_state *st = get_module_state(mod);
7481+
Py_CLEAR(st->module);
74827482
clear_state(st);
74837483

74847484
PyInterpreterState *interp = PyInterpreterState_Get();

0 commit comments

Comments
 (0)