diff options
author | Guido van Rossum <guido@python.org> | 2019-02-01 23:28:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-01 23:28:13 (GMT) |
commit | d2b4c19d53f5f021fb1c7c32d48033a92ac4fe49 (patch) | |
tree | b1ca771dd7a01d8b163741ab8ef841a7bc7ebf4c /Python/ast.c | |
parent | ac19081c26eaa7de3e6aabeb789ddc2e7cdd5b24 (diff) | |
download | cpython-d2b4c19d53f5f021fb1c7c32d48033a92ac4fe49.zip cpython-d2b4c19d53f5f021fb1c7c32d48033a92ac4fe49.tar.gz cpython-d2b4c19d53f5f021fb1c7c32d48033a92ac4fe49.tar.bz2 |
bpo-35879: Fix type comment leaks (GH-11728)
* Fix leak for # type: ignore
* Fix the type comment leak
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/ast.c b/Python/ast.c index c422e96..45578a8 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -699,11 +699,16 @@ ast_error(struct compiling *c, const node *n, const char *errmsg, ...) */ static string -new_type_comment(const char *s) +new_type_comment(const char *s, struct compiling *c) { - return PyUnicode_DecodeUTF8(s, strlen(s), NULL); + PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL); + if (PyArena_AddPyObject(c->c_arena, res) < 0) { + Py_DECREF(res); + return NULL; + } + return res; } -#define NEW_TYPE_COMMENT(n) new_type_comment(STR(n)) +#define NEW_TYPE_COMMENT(n) new_type_comment(STR(n), c) static int num_stmts(const node *n) |