Mercurial > cpython-lru_cache-weakref
diff Modules/parsermodule.c @ 84578:89c6495d1ff2
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.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Fri, 12 Jul 2013 01:33:59 +0200 |
| parents | 13e2e44db99d |
| children | c80a9705803a |
line wrap: on
line diff
--- a/Modules/parsermodule.c Fri Jul 12 00:53:57 2013 +0200 +++ b/Modules/parsermodule.c Fri Jul 12 01:33:59 2013 +0200 @@ -809,8 +809,13 @@ return 0; } strn = (char *)PyObject_MALLOC(len + 1); - if (strn != NULL) - (void) memcpy(strn, temp_str, len + 1); + if (strn == NULL) { + Py_DECREF(temp); + Py_XDECREF(elem); + PyErr_NoMemory(); + return 0; + } + (void) memcpy(strn, temp_str, len + 1); Py_DECREF(temp); } else if (!ISNONTERMINAL(type)) { @@ -906,8 +911,14 @@ return NULL; } res->n_str = (char *)PyObject_MALLOC(len + 1); - if (res->n_str != NULL && temp != NULL) - (void) memcpy(res->n_str, temp, len + 1); + if (res->n_str == NULL) { + 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(tuple); }
