From f72b2c8f0984002f25638b2ca341cd556b50f760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Le=C3=A9h?= <52788117+Ptrskay3@users.noreply.github.com> Date: Wed, 18 Aug 2021 12:50:57 +0200 Subject: [PATCH] Py_CompileString decref (#1810) * update changelog * fix memory leak in PyModule::from_code * add PR link to changelog * Add Py_DECREF also when PyImport_ExecCodeModuleEx fails * Remove duplicated calls, simplify logic Co-authored-by: messense Co-authored-by: messense --- CHANGELOG.md | 4 ++-- src/types/module.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7fe6726..fe3d8c14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,8 +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 `Python::run_code` which fixes a memory leak when - calling Python from Rust. [#1806](https://github.com/PyO3/pyo3/pull/1806) +- Add missing `Py_DECREF` to `Python::run_code` and `PyModule::from_code` which fixes a memory leak when + calling Python from Rust. [#1806](https://github.com/PyO3/pyo3/pull/1806), [#1810](https://github.com/PyO3/pyo3/pull/1810) ## [0.14.2] - 2021-08-09 diff --git a/src/types/module.rs b/src/types/module.rs index 4d9c4355..97bdef36 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -126,6 +126,7 @@ impl PyModule { } let mptr = ffi::PyImport_ExecCodeModuleEx(module.as_ptr(), cptr, filename.as_ptr()); + ffi::Py_DECREF(cptr); if mptr.is_null() { return Err(PyErr::api_call_failed(py)); }