mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Issue #18408: Fix parser.sequence2st() and parser.tuple2st(): raise MemoryError
on memory allocation failure Instead of ignoring the memory allocation failure and create invalid objects.
This commit is contained in:
parent
4202456cd4
commit
3bd6abd129
1 changed files with 15 additions and 4 deletions
|
@ -809,8 +809,13 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
strn = (char *)PyObject_MALLOC(len + 1);
|
strn = (char *)PyObject_MALLOC(len + 1);
|
||||||
if (strn != NULL)
|
if (strn == NULL) {
|
||||||
(void) memcpy(strn, temp_str, len + 1);
|
Py_DECREF(temp);
|
||||||
|
Py_XDECREF(elem);
|
||||||
|
PyErr_NoMemory();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
(void) memcpy(strn, temp_str, len + 1);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
}
|
}
|
||||||
else if (!ISNONTERMINAL(type)) {
|
else if (!ISNONTERMINAL(type)) {
|
||||||
|
@ -906,8 +911,14 @@ build_node_tree(PyObject *tuple)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
res->n_str = (char *)PyObject_MALLOC(len + 1);
|
res->n_str = (char *)PyObject_MALLOC(len + 1);
|
||||||
if (res->n_str != NULL && temp != NULL)
|
if (res->n_str == NULL) {
|
||||||
(void) memcpy(res->n_str, temp, len + 1);
|
Py_DECREF(res);
|
||||||
|
Py_DECREF(encoding);
|
||||||
|
Py_DECREF(tuple);
|
||||||
|
PyErr_NoMemory();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
(void) memcpy(res->n_str, temp, len + 1);
|
||||||
Py_DECREF(encoding);
|
Py_DECREF(encoding);
|
||||||
Py_DECREF(tuple);
|
Py_DECREF(tuple);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue