Skip to content

Commit 40d0e1c

Browse files
author
marat
committed
Fix refleaks
1 parent 375cf41 commit 40d0e1c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Modules/_datetimemodule.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,10 +2055,25 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
20552055
else if (ch == '-' && i < flen) {
20562056
Py_UCS4 next_ch = PyUnicode_READ_CHAR(format, i);
20572057
i++;
2058-
replacement = make_dash_replacement(object, next_ch, timetuple);
2059-
if (replacement == NULL) {
2058+
2059+
PyObject *tmp = make_dash_replacement(object, next_ch, timetuple);
2060+
if (tmp == NULL) {
2061+
Py_DECREF(tmp);
20602062
goto Error;
20612063
}
2064+
2065+
if (PyUnicodeWriter_WriteSubstring(writer, format, start, end) < 0) {
2066+
Py_DECREF(tmp);
2067+
goto Error;
2068+
}
2069+
start = i;
2070+
if (PyUnicodeWriter_WriteStr(writer, tmp) < 0) {
2071+
Py_DECREF(tmp);
2072+
goto Error;
2073+
}
2074+
2075+
Py_DECREF(tmp);
2076+
continue;
20622077
}
20632078
#endif
20642079
else {

0 commit comments

Comments
 (0)