]> granicus.if.org Git - python/commitdiff
Fix leaks in Python-ast.c (#16127)
authorEddie Elizondo <eelizondo@fb.com>
Sat, 14 Sep 2019 13:38:17 +0000 (09:38 -0400)
committerDino Viehland <dinoviehland@gmail.com>
Sat, 14 Sep 2019 13:38:17 +0000 (14:38 +0100)
Parser/asdl_c.py
Python/Python-ast.c

index 6b31ffd8315dc602d712b00afc1883c9638195fc..0b72f9ee236c5c8cf0ea8bd7985cd54628beda4b 100755 (executable)
@@ -638,9 +638,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
index 5190a90f13bf3fe463d76b673d4be4208f8aaca9..7a38e98c435ac43e4fb65dc366400ab76506bf16 100644 (file)
@@ -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