]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-150379: fix ref leak in C API monitoring events (#150381)
authorpengyu lee <lipengyu@kylinos.cn>
Mon, 25 May 2026 10:42:33 +0000 (18:42 +0800)
committerGitHub <noreply@github.com>
Mon, 25 May 2026 10:42:33 +0000 (16:12 +0530)
Python/instrumentation.c

index 51bcbfdb3b6c55b5fdc06cd1ecd0d8a80aa58697..0af2070b5cd983a4d23c0281e7f08bf324569bcd 100644 (file)
@@ -2630,8 +2630,9 @@ capi_call_instrumentation(PyMonitoringState *state, PyObject *codelike, int32_t
         PyErr_SetString(PyExc_ValueError, "offset must be non-negative");
         return -1;
     }
+    PyObject *offset_obj = NULL;
     if (event != PY_MONITORING_EVENT_LINE) {
-        PyObject *offset_obj = PyLong_FromLong(offset);
+        offset_obj = PyLong_FromLong(offset);
         if (offset_obj == NULL) {
             return -1;
         }
@@ -2672,6 +2673,7 @@ capi_call_instrumentation(PyMonitoringState *state, PyObject *codelike, int32_t
             }
         }
     }
+    Py_XDECREF(offset_obj);
     return err;
 }