Skip to content

Py_CompileString decref#1810

Merged
messense merged 5 commits intoPyO3:mainfrom
Ptrskay3:py_compilestring_decref
Aug 18, 2021
Merged

Py_CompileString decref#1810
messense merged 5 commits intoPyO3:mainfrom
Ptrskay3:py_compilestring_decref

Conversation

@Ptrskay3
Copy link
Contributor

This PR adds the missing Py_DECREF to PyModule::from_code similar to #1806. Py_CompileString returns a new owned pointer, and its reference count should be decremented, thus it's deallocated corretly.

This should close #1801.

@Ptrskay3 Ptrskay3 changed the title Py compilestring decref Py_CompileString decref Aug 18, 2021
Copy link
Member

@messense messense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Co-authored-by: messense <messense@icloud.com>
Copy link
Member

@messense messense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@messense messense enabled auto-merge (squash) August 18, 2021 10:49
@messense messense merged commit f72b2c8 into PyO3:main Aug 18, 2021
@mejrs mejrs mentioned this pull request Aug 20, 2021
davidhewitt pushed a commit that referenced this pull request Aug 21, 2021
* 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 <messense@icloud.com>

Co-authored-by: messense <messense@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential memory leak when calling Python from Rust

3 participants