]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-145376: Fix reference leaks in _lprof.c (#145539)
authorPieter Eendebak <pieter.eendebak@gmail.com>
Mon, 9 Mar 2026 12:50:45 +0000 (13:50 +0100)
committerGitHub <noreply@github.com>
Mon, 9 Mar 2026 12:50:45 +0000 (13:50 +0100)
Modules/_lsprof.c

index 025a3fac46e59babbabc59d5fdb9ede2c17e8b10..a2d1aefb1611b36e4299bec88f2a204b761612d2 100644 (file)
@@ -702,6 +702,7 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje
         if (PyCFunction_Check(meth)) {
             return (PyObject*)((PyCFunctionObject *)meth);
         }
+        Py_DECREF(meth);
     }
     return NULL;
 }
@@ -961,6 +962,8 @@ profiler_traverse(PyObject *op, visitproc visit, void *arg)
     ProfilerObject *self = ProfilerObject_CAST(op);
     Py_VISIT(Py_TYPE(op));
     Py_VISIT(self->externalTimer);
+    Py_VISIT(self->missing);
+
     return 0;
 }
 
@@ -979,6 +982,7 @@ profiler_dealloc(PyObject *op)
 
     flush_unmatched(self);
     clearEntries(self);
+    Py_XDECREF(self->missing);
     Py_XDECREF(self->externalTimer);
     PyTypeObject *tp = Py_TYPE(self);
     tp->tp_free(self);
@@ -1017,7 +1021,7 @@ profiler_init_impl(ProfilerObject *self, PyObject *timer, double timeunit,
     if (!monitoring) {
         return -1;
     }
-    self->missing = PyObject_GetAttrString(monitoring, "MISSING");
+    Py_XSETREF(self->missing, PyObject_GetAttrString(monitoring, "MISSING"));
     if (!self->missing) {
         Py_DECREF(monitoring);
         return -1;