[Python-checkins] bpo-41995: Handle allocation failure in _tracemalloc and _zoneinfo (GH-22635)

miss-islington webhook-mailer at python.org
Wed Jan 20 04:03:37 EST 2021


https://github.com/python/cpython/commit/50938b63fbb0d4bed24dceccf188b8d0fe58463c
commit: 50938b63fbb0d4bed24dceccf188b8d0fe58463c
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-01-20T01:03:28-08:00
summary:

bpo-41995: Handle allocation failure in _tracemalloc and _zoneinfo (GH-22635)

(cherry picked from commit f1ff800db1f9fa5ff8f2fa2863796a46bfa9ee46)

Co-authored-by: Yunlongs <lylgood at foxmail.com>

files:
M Modules/_zoneinfo.c

diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index fafb6b01df371..d87a20100a221 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -909,7 +909,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);
@@ -991,6 +997,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) {
@@ -1006,6 +1015,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);



More information about the Python-checkins mailing list