From cf39181efd36dcc26e25d5f09629133e063fc2c5 Mon Sep 17 00:00:00 2001 From: Peter Schafhalter Date: Tue, 17 Aug 2021 14:21:56 -0700 Subject: [PATCH 1/3] Fix memory leak when calling Python from Rust --- src/python.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python.rs b/src/python.rs index 176474156ec..3ded9283c98 100644 --- a/src/python.rs +++ b/src/python.rs @@ -396,6 +396,7 @@ impl<'p> Python<'p> { return Err(PyErr::api_call_failed(self)); } let res_ptr = ffi::PyEval_EvalCode(code_obj, globals, locals); + ffi::Py_DECREF(code_obj); self.from_owned_ptr_or_err(res_ptr) } From e4466549e5f6241d9550648040958c01a6a743c4 Mon Sep 17 00:00:00 2001 From: Peter Schafhalter Date: Tue, 17 Aug 2021 14:37:39 -0700 Subject: [PATCH 2/3] Edit changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 699f4df4a4b..7870ee23102 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Loosened the lower bound on the `num-complex` optional dependency to support interop with `rust-numpy` and `ndarray` when building with the MSRV of 1.41 [#1799](https://github.com/PyO3/pyo3/pull/1799) +- Add missing `Py_DECREF` to fix memory leak when calling Python from Rust. [#1806](https://github.com/PyO3/pyo3/pull/1806) ## [0.14.2] - 2021-08-09 From 37ea57de2bacbff8d37e1fb96630bc939f3377f6 Mon Sep 17 00:00:00 2001 From: Peter Schafhalter Date: Tue, 17 Aug 2021 22:56:27 -0700 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7870ee23102..c7fe6726913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Loosened the lower bound on the `num-complex` optional dependency to support interop with `rust-numpy` and `ndarray` when building with the MSRV of 1.41 [#1799](https://github.com/PyO3/pyo3/pull/1799) -- Add missing `Py_DECREF` to fix memory leak when calling Python from Rust. [#1806](https://github.com/PyO3/pyo3/pull/1806) +- Add missing `Py_DECREF` to `Python::run_code` which fixes a memory leak when + calling Python from Rust. [#1806](https://github.com/PyO3/pyo3/pull/1806) ## [0.14.2] - 2021-08-09