mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #28408: Fixed a leak and remove redundant code in _PyUnicodeWriter_Finish().
Patch by Xiang Zhang.
This commit is contained in:
		
							parent
							
								
									c3adf1e09b
								
							
						
					
					
						commit
						c8bc3d1c07
					
				
					 1 changed files with 12 additions and 18 deletions
				
			
		|  | @ -13570,34 +13570,28 @@ PyObject * | |||
| _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer) | ||||
| { | ||||
|     PyObject *str; | ||||
| 
 | ||||
|     if (writer->pos == 0) { | ||||
|         Py_CLEAR(writer->buffer); | ||||
|         _Py_RETURN_UNICODE_EMPTY(); | ||||
|     } | ||||
|     if (writer->readonly) { | ||||
| 
 | ||||
|     str = writer->buffer; | ||||
|     writer->buffer = NULL; | ||||
| 
 | ||||
|     if (writer->readonly) { | ||||
|         assert(PyUnicode_GET_LENGTH(str) == writer->pos); | ||||
|         return str; | ||||
|     } | ||||
|     if (writer->pos == 0) { | ||||
|         Py_CLEAR(writer->buffer); | ||||
| 
 | ||||
|         /* Get the empty Unicode string singleton ('') */ | ||||
|         _Py_INCREF_UNICODE_EMPTY(); | ||||
|         str  = unicode_empty; | ||||
|     } | ||||
|     else { | ||||
|         str = writer->buffer; | ||||
|         writer->buffer = NULL; | ||||
| 
 | ||||
|     if (PyUnicode_GET_LENGTH(str) != writer->pos) { | ||||
|         PyObject *str2; | ||||
|         str2 = resize_compact(str, writer->pos); | ||||
|             if (str2 == NULL) | ||||
|         if (str2 == NULL) { | ||||
|             Py_DECREF(str); | ||||
|             return NULL; | ||||
|             str = str2; | ||||
|         } | ||||
|         str = str2; | ||||
|     } | ||||
| 
 | ||||
|     assert(_PyUnicode_CheckConsistency(str, 1)); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka