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/_tracemalloc.c | |
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/_tracemalloc.c')
-rw-r--r-- | Modules/_tracemalloc.c | 19 |
1 files changed, 9 insertions, 10 deletions
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); |