[Python-checkins] Fix leaks in Python-ast.c (#16127)

Dino Viehland webhook-mailer at python.org
Sat Sep 14 09:38:21 EDT 2019


https://github.com/python/cpython/commit/0247e80f3c529900689425676342cb70ea31a13d
commit: 0247e80f3c529900689425676342cb70ea31a13d
branch: master
author: Eddie Elizondo <eelizondo at fb.com>
committer: Dino Viehland <dinoviehland at gmail.com>
date: 2019-09-14T14:38:17+01:00
summary:

Fix leaks in Python-ast.c (#16127)

files:
M Parser/asdl_c.py
M Python/Python-ast.c

diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 6b31ffd8315d..0b72f9ee236c 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -638,9 +638,13 @@ def visitModule(self, mod):
 ast_dealloc(AST_object *self)
 {
     /* bpo-31095: UnTrack is needed before calling any callbacks */
+    PyTypeObject *tp = Py_TYPE(self);
     PyObject_GC_UnTrack(self);
     Py_CLEAR(self->dict);
-    Py_TYPE(self)->tp_free(self);
+    freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
+    assert(free_func != NULL);
+    free_func(self);
+    Py_DECREF(tp);
 }
 
 static int
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 5190a90f13bf..7a38e98c435a 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -1130,9 +1130,13 @@ static void
 ast_dealloc(AST_object *self)
 {
     /* bpo-31095: UnTrack is needed before calling any callbacks */
+    PyTypeObject *tp = Py_TYPE(self);
     PyObject_GC_UnTrack(self);
     Py_CLEAR(self->dict);
-    Py_TYPE(self)->tp_free(self);
+    freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
+    assert(free_func != NULL);
+    free_func(self);
+    Py_DECREF(tp);
 }
 
 static int



More information about the Python-checkins mailing list