Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1ff800

Browse files
authored
bpo-41995: Handle allocation failure in _tracemalloc and _zoneinfo (GH-22635)
1 parent d6d6371 commit f1ff800

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
@@ -904,7 +904,13 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
904904
// Load the transition indices and list
905905
self->trans_list_utc =
906906
PyMem_Malloc(self->num_transitions * sizeof(int64_t));
907+
if (self->trans_list_utc == NULL) {
908+
goto error;
909+
}
907910
trans_idx = PyMem_Malloc(self->num_transitions * sizeof(Py_ssize_t));
911+
if (trans_idx == NULL) {
912+
goto error;
913+
}
908914

909915
for (size_t i = 0; i < self->num_transitions; ++i) {
910916
PyObject *num = PyTuple_GetItem(trans_utc, i);
@@ -986,6 +992,9 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
986992

987993
// Build _ttinfo objects from utcoff, dstoff and abbr
988994
self->_ttinfos = PyMem_Malloc(self->num_ttinfos * sizeof(_ttinfo));
995+
if (self->_ttinfos == NULL) {
996+
goto error;
997+
}
989998
for (size_t i = 0; i < self->num_ttinfos; ++i) {
990999
PyObject *tzname = PyTuple_GetItem(abbr, i);
9911000
if (tzname == NULL) {
@@ -1001,6 +1010,9 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
10011010
// Build our mapping from transition to the ttinfo that applies
10021011
self->trans_ttinfos =
10031012
PyMem_Calloc(self->num_transitions, sizeof(_ttinfo *));
1013+
if (self->trans_ttinfos == NULL) {
1014+
goto error;
1015+
}
10041016
for (size_t i = 0; i < self->num_transitions; ++i) {
10051017
size_t ttinfo_idx = trans_idx[i];
10061018
assert(ttinfo_idx < self->num_ttinfos);

0 commit comments

Comments
 (0)