diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-28 23:28:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 23:28:13 (GMT) |
commit | 8852ad4208e34825f74e24945edb5bcf055d94fe (patch) | |
tree | 157f239ba46634301e136f4662b1646f7258357e /Modules | |
parent | 5e8c691594d68925213d36296ce7c4b3e90bcb1d (diff) | |
download | cpython-8852ad4208e34825f74e24945edb5bcf055d94fe.zip cpython-8852ad4208e34825f74e24945edb5bcf055d94fe.tar.gz cpython-8852ad4208e34825f74e24945edb5bcf055d94fe.tar.bz2 |
bpo-40429: PyFrame_GetCode() now returns a strong reference (GH-19773)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_lsprof.c | 7 | ||||
-rw-r--r-- | Modules/_tracemalloc.c | 19 |
2 files changed, 15 insertions, 11 deletions
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 39cf6e1..5e53d83 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -390,14 +390,19 @@ profiler_callback(PyObject *self, PyFrameObject *frame, int what, { PyCodeObject *code = PyFrame_GetCode(frame); ptrace_enter_call(self, (void *)code, (PyObject *)code); + Py_DECREF(code); break; } /* the 'frame' of a called function is about to finish (either normally or with an exception) */ case PyTrace_RETURN: - ptrace_leave_call(self, (void *)PyFrame_GetCode(frame)); + { + PyCodeObject *code = PyFrame_GetCode(frame); + ptrace_leave_call(self, (void *)code); + Py_DECREF(code); break; + } /* case PyTrace_EXCEPTION: If the exception results in the function exiting, a diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index b2a0003..24628a9 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -335,26 +335,24 @@ hashtable_compare_traceback(_Py_hashtable_t *ht, const void *pkey, static void tracemalloc_get_frame(PyFrameObject *pyframe, frame_t *frame) { - PyCodeObject *code; - PyObject *filename; - _Py_hashtable_entry_t *entry; - int lineno; - frame->filename = unknown_filename; - lineno = PyFrame_GetLineNumber(pyframe); - if (lineno < 0) + int lineno = PyFrame_GetLineNumber(pyframe); + if (lineno < 0) { lineno = 0; + } frame->lineno = (unsigned int)lineno; - code = PyFrame_GetCode(pyframe); - if (code->co_filename == NULL) { + PyCodeObject *code = PyFrame_GetCode(pyframe); + PyObject *filename = code->co_filename; + Py_DECREF(code); + + if (filename == NULL) { #ifdef TRACE_DEBUG tracemalloc_error("failed to get the filename of the code object"); #endif return; } - filename = code->co_filename; assert(filename != NULL); if (filename == NULL) return; @@ -375,6 +373,7 @@ tracemalloc_get_frame(PyFrameObject *pyframe, frame_t *frame) } /* intern the filename */ + _Py_hashtable_entry_t *entry; entry = _Py_HASHTABLE_GET_ENTRY(tracemalloc_filenames, filename); if (entry != NULL) { _Py_HASHTABLE_ENTRY_READ_KEY(tracemalloc_filenames, entry, filename); |