mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	bpo-41995: Handle allocation failure in _tracemalloc and _zoneinfo (GH-22635)
(cherry picked from commit f1ff800db1)
Co-authored-by: Yunlongs <lylgood@foxmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									c347cbe694
								
							
						
					
					
						commit
						50938b63fb
					
				
					 1 changed files with 12 additions and 0 deletions
				
			
		| 
						 | 
					@ -909,7 +909,13 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
 | 
				
			||||||
    // Load the transition indices and list
 | 
					    // Load the transition indices and list
 | 
				
			||||||
    self->trans_list_utc =
 | 
					    self->trans_list_utc =
 | 
				
			||||||
        PyMem_Malloc(self->num_transitions * sizeof(int64_t));
 | 
					        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));
 | 
					    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) {
 | 
					    for (size_t i = 0; i < self->num_transitions; ++i) {
 | 
				
			||||||
        PyObject *num = PyTuple_GetItem(trans_utc, 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
 | 
					    // Build _ttinfo objects from utcoff, dstoff and abbr
 | 
				
			||||||
    self->_ttinfos = PyMem_Malloc(self->num_ttinfos * sizeof(_ttinfo));
 | 
					    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) {
 | 
					    for (size_t i = 0; i < self->num_ttinfos; ++i) {
 | 
				
			||||||
        PyObject *tzname = PyTuple_GetItem(abbr, i);
 | 
					        PyObject *tzname = PyTuple_GetItem(abbr, i);
 | 
				
			||||||
        if (tzname == NULL) {
 | 
					        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
 | 
					    // Build our mapping from transition to the ttinfo that applies
 | 
				
			||||||
    self->trans_ttinfos =
 | 
					    self->trans_ttinfos =
 | 
				
			||||||
        PyMem_Calloc(self->num_transitions, sizeof(_ttinfo *));
 | 
					        PyMem_Calloc(self->num_transitions, sizeof(_ttinfo *));
 | 
				
			||||||
 | 
					    if (self->trans_ttinfos == NULL) {
 | 
				
			||||||
 | 
					        goto error;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    for (size_t i = 0; i < self->num_transitions; ++i) {
 | 
					    for (size_t i = 0; i < self->num_transitions; ++i) {
 | 
				
			||||||
        size_t ttinfo_idx = trans_idx[i];
 | 
					        size_t ttinfo_idx = trans_idx[i];
 | 
				
			||||||
        assert(ttinfo_idx < self->num_ttinfos);
 | 
					        assert(ttinfo_idx < self->num_ttinfos);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue