Skip to content

Commit ede4415

Browse files
Fix refleaks.
1 parent a309474 commit ede4415

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Modules/_datetimemodule.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7059,8 +7059,12 @@ _datetime_exec(PyObject *module)
70597059
}
70607060
}
70617061

7062+
/* For now we only set the objects on the static types once.
7063+
* We will relax that once each types __dict__ is per-interpreter. */
70627064
#define DATETIME_ADD_MACRO(dict, c, value_expr) \
70637065
do { \
7066+
if (PyDict_GetItemString(dict, c) == NULL) { \
7067+
assert(!PyErr_Occurred()); \
70647068
PyObject *value = (value_expr); \
70657069
if (value == NULL) { \
70667070
goto error; \
@@ -7070,6 +7074,7 @@ _datetime_exec(PyObject *module)
70707074
goto error; \
70717075
} \
70727076
Py_DECREF(value); \
7077+
} \
70737078
} while(0)
70747079

70757080
/* timedelta values */
@@ -7117,6 +7122,8 @@ _datetime_exec(PyObject *module)
71177122
PyObject *max = create_timezone_from_delta(0, (23 * 60 + 59) * 60, 0, 0);
71187123
DATETIME_ADD_MACRO(d, "max", max);
71197124

7125+
#undef DATETIME_ADD_MACRO
7126+
71207127
/* Add module level attributes */
71217128
if (PyModule_AddIntMacro(module, MINYEAR) < 0) {
71227129
goto error;
@@ -7171,7 +7178,6 @@ _datetime_exec(PyObject *module)
71717178
Py_XDECREF(old_module);
71727179
return rc;
71737180
}
7174-
#undef DATETIME_ADD_MACRO
71757181

71767182
static PyModuleDef_Slot module_slots[] = {
71777183
{Py_mod_exec, _datetime_exec},

0 commit comments

Comments
 (0)