Skip to content

Commit

Permalink
Apparently, PySet_Add does not steal a reference, hence we should not…
Browse files Browse the repository at this point in the history
… forget to clean up ours.
  • Loading branch information
adamreichold authored and davidhewitt committed Jul 3, 2023
1 parent efea50b commit 1812274
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 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 creating `PySet` or `PyFrozenSet` or returning types converted into these internally, e.g. `HashSet` or `BTreeSet`.
4 changes: 2 additions & 2 deletions src/types/frozenset.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, PyObject,
Py, PyObject,
};
use crate::{ffi, AsPyPointer, PyAny, Python, ToPyObject};

Expand Down Expand Up @@ -209,7 +209,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
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 @@ -250,7 +250,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 1812274

Please sign in to comment.