Skip to content

Commit 01f9398

Browse files
committed
Fix refleak and null pointer deref in datetimemodule
1 parent 671a953 commit 01f9398

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

Modules/_datetimemodule.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,9 +3822,26 @@ iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
38223822
return NULL;
38233823
}
38243824

3825-
PyTuple_SET_ITEM(self, 0, PyLong_FromLong(year));
3826-
PyTuple_SET_ITEM(self, 1, PyLong_FromLong(week));
3827-
PyTuple_SET_ITEM(self, 2, PyLong_FromLong(weekday));
3825+
PyObject *year_object = PyLong_FromLong(year);
3826+
if (year_object == NULL) {
3827+
Py_DECREF(self);
3828+
return NULL;
3829+
}
3830+
PyTuple_SET_ITEM(self, 0, year_object);
3831+
3832+
PyObject *week_object = PyLong_FromLong(week);
3833+
if (week_object == NULL) {
3834+
Py_DECREF(self);
3835+
return NULL;
3836+
}
3837+
PyTuple_SET_ITEM(self, 1, week_object);
3838+
3839+
PyObject *weekday_object = PyLong_FromLong(weekday);
3840+
if (weekday_object == NULL) {
3841+
Py_DECREF(self);
3842+
return NULL;
3843+
}
3844+
PyTuple_SET_ITEM(self, 2, weekday_object);
38283845

38293846
return (PyObject *)self;
38303847
}
@@ -6891,9 +6908,9 @@ datetime_datetime_astimezone_impl(PyDateTime_DateTime *self,
68916908
goto naive;
68926909
}
68936910
else if (!PyDelta_Check(offset)) {
6894-
Py_DECREF(offset);
68956911
PyErr_Format(PyExc_TypeError, "utcoffset() returned %.200s,"
68966912
" expected timedelta or None", Py_TYPE(offset)->tp_name);
6913+
Py_DECREF(offset);
68976914
return NULL;
68986915
}
68996916
/* result = self - offset */

0 commit comments

Comments
 (0)