Merge pull request #3286 from PyO3/set-add-does-not-steal

Apparently, PySet_Add does not steal a reference, hence we should not forget to clean up ours.
This commit is contained in:
David Hewitt 2023-07-02 20:06:51 +00:00 committed by GitHub
commit 1a0c9bec61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View file

@ -0,0 +1 @@
Fix memory leak when creating `PySet` or `PyFrozenSet` or returning types converted into these internally, e.g. `HashSet` or `BTreeSet`.

View file

@ -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};
@ -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()))?;
}
}

View file

@ -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;
@ -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()))?;
}
}