@@ -310,20 +310,27 @@ index 8c9ed1d7..5183a325 100644
310
310
}
311
311
}
312
312
diff --git a/torch/csrc/jit/python/python_tracer.cpp b/torch/csrc/jit/python/python_tracer.cpp
313
- index 78676e2e..ecc76ea9 100644
313
+ index 78676e2e..e6a3caf0 100644
314
314
--- a/torch/csrc/jit/python/python_tracer.cpp
315
315
+++ b/torch/csrc/jit/python/python_tracer.cpp
316
- @@ -33,8 +33,8 @@ std::vector<StackEntry> _pythonCallstack() {
316
+ @@ -33,11 +33,15 @@ std::vector<StackEntry> _pythonCallstack() {
317
317
while (nullptr != frame) {
318
318
auto code = THPCodeObjectPtr(PyFrame_GetCode(frame));
319
319
size_t line = PyCode_Addr2Line(code.get(), PyFrame_GetLasti(frame));
320
320
- std::string filename = THPUtils_unpackString(code->co_filename);
321
321
- std::string funcname = THPUtils_unpackString(code->co_name);
322
- + std::string filename = THPUtils_unpackString(PyCode_GetFileName(code));
323
- + std::string funcname = THPUtils_unpackString(PyCode_GetName(code));
322
+ + PyObject* filenameObj = PyCode_GetFileName(code);
323
+ + std::string filename = THPUtils_unpackString(filenameObj);
324
+ + PyObject* funcnameObj = PyCode_GetName(code);
325
+ + std::string funcname = THPUtils_unpackString(funcnameObj);
324
326
auto source = std::make_shared<Source>(funcname, filename, line);
325
327
entries.emplace_back(
326
328
StackEntry{funcname, SourceRange(source, 0, funcname.size())});
329
+ + Py_DECREF(funcnameObj);
330
+ + Py_DECREF(filenameObj);
331
+ auto new_frame = PyFrame_GetBack(frame);
332
+ Py_DECREF(frame);
333
+ frame = new_frame;
327
334
diff --git a/torch/csrc/utils/python_compat.h b/torch/csrc/utils/python_compat.h
328
335
index 44911527..d3ad9c54 100644
329
336
--- a/torch/csrc/utils/python_compat.h
0 commit comments