Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ zoneinfo_new_instance(zoneinfo_state *state, PyTypeObject *type, PyObject *key)

goto cleanup;
error:
assert(PyErr_Occurred());
Py_CLEAR(self);
cleanup:
if (file_obj != NULL) {
Expand Down Expand Up @@ -458,6 +459,7 @@ zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type, PyTypeObject *cls,
return (PyObject *)self;

error:
assert(PyErr_Occurred());
Py_XDECREF(file_repr);
Py_XDECREF(self);
return NULL;
Expand Down Expand Up @@ -1043,10 +1045,12 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
self->trans_list_utc =
PyMem_Malloc(self->num_transitions * sizeof(int64_t));
if (self->trans_list_utc == NULL) {
PyErr_NoMemory();
goto error;
}
trans_idx = PyMem_Malloc(self->num_transitions * sizeof(Py_ssize_t));
if (trans_idx == NULL) {
PyErr_NoMemory();
goto error;
}

Expand Down Expand Up @@ -1086,6 +1090,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
isdst = PyMem_Malloc(self->num_ttinfos * sizeof(unsigned char));

if (utcoff == NULL || isdst == NULL) {
PyErr_NoMemory();
goto error;
}
for (size_t i = 0; i < self->num_ttinfos; ++i) {
Expand Down Expand Up @@ -1115,6 +1120,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)

dstoff = PyMem_Calloc(self->num_ttinfos, sizeof(long));
if (dstoff == NULL) {
PyErr_NoMemory();
goto error;
}

Expand All @@ -1131,6 +1137,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
// Build _ttinfo objects from utcoff, dstoff and abbr
self->_ttinfos = PyMem_Malloc(self->num_ttinfos * sizeof(_ttinfo));
if (self->_ttinfos == NULL) {
PyErr_NoMemory();
goto error;
}
for (size_t i = 0; i < self->num_ttinfos; ++i) {
Expand All @@ -1151,6 +1158,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
self->trans_ttinfos =
PyMem_Calloc(self->num_transitions, sizeof(_ttinfo *));
if (self->trans_ttinfos == NULL) {
PyErr_NoMemory();
goto error;
}
for (size_t i = 0; i < self->num_transitions; ++i) {
Expand Down Expand Up @@ -1902,6 +1910,7 @@ parse_transition_rule(const char **p, TransitionRuleType **out)

DayRule *rv = PyMem_Calloc(1, sizeof(DayRule));
if (rv == NULL) {
PyErr_NoMemory();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_tz_str will then also raise a PyExc_ValueError, this will be confusing for users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't want to raise MemoryError in parse_transition_rule(). I revert this change.

return -1;
}

Expand Down Expand Up @@ -2135,6 +2144,7 @@ ts_to_local(size_t *trans_idx, int64_t *trans_utc, long *utcoff,
for (size_t i = 0; i < 2; ++i) {
trans_local[i] = PyMem_Malloc(num_transitions * sizeof(int64_t));
if (trans_local[i] == NULL) {
PyErr_NoMemory();
return -1;
}

Expand Down
Loading