summaryrefslogtreecommitdiffstats
path: root/Parser/asdl_c.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2020-02-06 14:45:46 (GMT)
committerGitHub <noreply@github.com>2020-02-06 14:45:46 (GMT)
commitd2f96672642cc51b92f61b951ca1b11d615c12d1 (patch)
tree51220398d618353d5ed1ba3fdceb0e1194a57b50 /Parser/asdl_c.py
parent54b4f14712b9350f11c983f1c8ac47a3716958a7 (diff)
downloadcpython-d2f96672642cc51b92f61b951ca1b11d615c12d1.zip
cpython-d2f96672642cc51b92f61b951ca1b11d615c12d1.tar.gz
cpython-d2f96672642cc51b92f61b951ca1b11d615c12d1.tar.bz2
bpo-38823: Fix refleaks in _ast initialization error path (GH-17276)
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-xParser/asdl_c.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index daac096..e81506c 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -998,17 +998,25 @@ class ASTModuleVisitor(PickleVisitor):
self.emit("if (!init_types()) return NULL;", 1)
self.emit('m = PyState_FindModule(&_astmodule);', 1)
self.emit("if (!m) return NULL;", 1)
+ self.emit('if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {', 1)
+ self.emit('goto error;', 2)
+ self.emit('}', 1)
self.emit('Py_INCREF(astmodulestate(m)->AST_type);', 1)
- self.emit('if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) return NULL;', 1)
- self.emit('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0)', 1)
- self.emit("return NULL;", 2)
- self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)', 1)
- self.emit("return NULL;", 2)
- self.emit('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0)', 1)
- self.emit("return NULL;", 2)
+ self.emit('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {', 1)
+ self.emit("goto error;", 2)
+ self.emit('}', 1)
+ self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {', 1)
+ self.emit("goto error;", 2)
+ self.emit('}', 1)
+ self.emit('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {', 1)
+ self.emit("goto error;", 2)
+ self.emit('}', 1)
for dfn in mod.dfns:
self.visit(dfn)
self.emit("return m;", 1)
+ self.emit("error:", 0)
+ self.emit("Py_DECREF(m);", 1)
+ self.emit("return NULL;", 1)
self.emit("}", 0)
def visitProduct(self, prod, name):
@@ -1024,7 +1032,9 @@ class ASTModuleVisitor(PickleVisitor):
def addObj(self, name):
self.emit("if (PyModule_AddObject(m, \"%s\", "
- "astmodulestate_global->%s_type) < 0) return NULL;" % (name, name), 1)
+ "astmodulestate_global->%s_type) < 0) {" % (name, name), 1)
+ self.emit("goto error;", 2)
+ self.emit('}', 1)
self.emit("Py_INCREF(astmodulestate(m)->%s_type);" % name, 1)