mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #14909: A number of places were using PyMem_Realloc() apis and
PyObject_GC_Resize() with incorrect error handling. In case of errors, the original object would be leaked. This checkin fixes those cases.
This commit is contained in:
parent
56517e5cb9
commit
85634d7a2e
5 changed files with 20 additions and 11 deletions
|
@ -8343,13 +8343,15 @@ charmaptranslate_makespace(Py_UCS4 **outobj, Py_ssize_t *psize,
|
|||
Py_ssize_t requiredsize)
|
||||
{
|
||||
Py_ssize_t oldsize = *psize;
|
||||
Py_UCS4 *new_outobj;
|
||||
if (requiredsize > oldsize) {
|
||||
/* exponentially overallocate to minimize reallocations */
|
||||
if (requiredsize < 2 * oldsize)
|
||||
requiredsize = 2 * oldsize;
|
||||
*outobj = PyMem_Realloc(*outobj, requiredsize * sizeof(Py_UCS4));
|
||||
if (*outobj == 0)
|
||||
new_outobj = PyMem_Realloc(*outobj, requiredsize * sizeof(Py_UCS4));
|
||||
if (new_outobj == 0)
|
||||
return -1;
|
||||
*outobj = new_outobj;
|
||||
*psize = requiredsize;
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue