Skip to content

Commit 50938b6

Browse files
bpo-41995: Handle allocation failure in _tracemalloc and _zoneinfo (GH-22635)
(cherry picked from commit f1ff800) Co-authored-by: Yunlongs <[email protected]>
1 parent c347cbe commit 50938b6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Modules/_zoneinfo.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,13 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
909909
// Load the transition indices and list
910910
self->trans_list_utc =
911911
PyMem_Malloc(self->num_transitions * sizeof(int64_t));
912+
if (self->trans_list_utc == NULL) {
913+
goto error;
914+
}
912915
trans_idx = PyMem_Malloc(self->num_transitions * sizeof(Py_ssize_t));
916+
if (trans_idx == NULL) {
917+
goto error;
918+
}
913919

914920
for (size_t i = 0; i < self->num_transitions; ++i) {
915921
PyObject *num = PyTuple_GetItem(trans_utc, i);
@@ -991,6 +997,9 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
991997

992998
// Build _ttinfo objects from utcoff, dstoff and abbr
993999
self->_ttinfos = PyMem_Malloc(self->num_ttinfos * sizeof(_ttinfo));
1000+
if (self->_ttinfos == NULL) {
1001+
goto error;
1002+
}
9941003
for (size_t i = 0; i < self->num_ttinfos; ++i) {
9951004
PyObject *tzname = PyTuple_GetItem(abbr, i);
9961005
if (tzname == NULL) {
@@ -1006,6 +1015,9 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
10061015
// Build our mapping from transition to the ttinfo that applies
10071016
self->trans_ttinfos =
10081017
PyMem_Calloc(self->num_transitions, sizeof(_ttinfo *));
1018+
if (self->trans_ttinfos == NULL) {
1019+
goto error;
1020+
}
10091021
for (size_t i = 0; i < self->num_transitions; ++i) {
10101022
size_t ttinfo_idx = trans_idx[i];
10111023
assert(ttinfo_idx < self->num_ttinfos);

0 commit comments

Comments
 (0)