Skip to content

Commit 78b924d

Browse files
authored
Merge pull request #1806 from pschafhalter/fix-memory-leak
Fix memory leak when calling Python from Rust
2 parents fc90092 + 37ea57d commit 78b924d

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2828
- Loosened the lower bound on the `num-complex` optional dependency to support
2929
interop with `rust-numpy` and `ndarray` when building with the MSRV of 1.41
3030
[#1799](https://github.com/PyO3/pyo3/pull/1799)
31+
- Add missing `Py_DECREF` to `Python::run_code` which fixes a memory leak when
32+
calling Python from Rust. [#1806](https://github.com/PyO3/pyo3/pull/1806)
3133

3234
## [0.14.2] - 2021-08-09
3335

src/python.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ impl<'p> Python<'p> {
396396
return Err(PyErr::api_call_failed(self));
397397
}
398398
let res_ptr = ffi::PyEval_EvalCode(code_obj, globals, locals);
399+
ffi::Py_DECREF(code_obj);
399400

400401
self.from_owned_ptr_or_err(res_ptr)
401402
}

0 commit comments

Comments
 (0)