Skip to content

Commit

Permalink
Apparently, PySet_Add does not steal a reference, hence we should for…
Browse files Browse the repository at this point in the history
…get to clean up ours.
  • Loading branch information
adamreichold committed Jul 2, 2023
1 parent 135535e commit a2594f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/3286.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix memory leak when returning types converted into `PySet` internally, e.g. `HashSet` or `BTreeSet`.
4 changes: 2 additions & 2 deletions src/types/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::types::PyIterator;
use crate::{
err::{self, PyErr, PyResult},
IntoPyPointer, Py,
Py,
};
use crate::{ffi, AsPyPointer, PyAny, PyObject, Python, ToPyObject};
use std::ptr;
Expand Down Expand Up @@ -260,7 +260,7 @@ pub(crate) fn new_from_iter<T: ToPyObject>(

for obj in elements {
unsafe {
err::error_on_minusone(py, ffi::PySet_Add(ptr, obj.into_ptr()))?;
err::error_on_minusone(py, ffi::PySet_Add(ptr, obj.as_ptr()))?;
}
}

Expand Down

0 comments on commit a2594f9

Please sign in to comment.