diff options
author | Yunlongs <lylgood@foxmail.com> | 2021-01-20 08:38:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 08:38:28 (GMT) |
commit | f1ff800db1f9fa5ff8f2fa2863796a46bfa9ee46 (patch) | |
tree | 381351d69d4bc2f9afbb8f20c18d6594b0133ac1 | |
parent | d6d6371447357c9c69b093657bbbb3977a3e60f2 (diff) | |
download | cpython-f1ff800db1f9fa5ff8f2fa2863796a46bfa9ee46.zip cpython-f1ff800db1f9fa5ff8f2fa2863796a46bfa9ee46.tar.gz cpython-f1ff800db1f9fa5ff8f2fa2863796a46bfa9ee46.tar.bz2 |
bpo-41995: Handle allocation failure in _tracemalloc and _zoneinfo (GH-22635)
-rw-r--r-- | Modules/_zoneinfo.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index bb32b14..d1e0934 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -904,7 +904,13 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj) // Load the transition indices and list self->trans_list_utc = PyMem_Malloc(self->num_transitions * sizeof(int64_t)); + if (self->trans_list_utc == NULL) { + goto error; + } trans_idx = PyMem_Malloc(self->num_transitions * sizeof(Py_ssize_t)); + if (trans_idx == NULL) { + goto error; + } for (size_t i = 0; i < self->num_transitions; ++i) { PyObject *num = PyTuple_GetItem(trans_utc, i); @@ -986,6 +992,9 @@ load_data(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) { + goto error; + } for (size_t i = 0; i < self->num_ttinfos; ++i) { PyObject *tzname = PyTuple_GetItem(abbr, i); if (tzname == NULL) { @@ -1001,6 +1010,9 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj) // Build our mapping from transition to the ttinfo that applies self->trans_ttinfos = PyMem_Calloc(self->num_transitions, sizeof(_ttinfo *)); + if (self->trans_ttinfos == NULL) { + goto error; + } for (size_t i = 0; i < self->num_transitions; ++i) { size_t ttinfo_idx = trans_idx[i]; assert(ttinfo_idx < self->num_ttinfos); |