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:
commit
1a0c9bec61
1
newsfragments/3286.fixed.md
Normal file
1
newsfragments/3286.fixed.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix memory leak when creating `PySet` or `PyFrozenSet` or returning types converted into these internally, e.g. `HashSet` or `BTreeSet`.
|
|
@ -2,7 +2,7 @@
|
||||||
use crate::types::PyIterator;
|
use crate::types::PyIterator;
|
||||||
use crate::{
|
use crate::{
|
||||||
err::{self, PyErr, PyResult},
|
err::{self, PyErr, PyResult},
|
||||||
IntoPyPointer, Py, PyObject,
|
Py, PyObject,
|
||||||
};
|
};
|
||||||
use crate::{ffi, AsPyPointer, PyAny, Python, ToPyObject};
|
use crate::{ffi, AsPyPointer, PyAny, Python, ToPyObject};
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ pub(crate) fn new_from_iter<T: ToPyObject>(
|
||||||
|
|
||||||
for obj in elements {
|
for obj in elements {
|
||||||
unsafe {
|
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()))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
use crate::types::PyIterator;
|
use crate::types::PyIterator;
|
||||||
use crate::{
|
use crate::{
|
||||||
err::{self, PyErr, PyResult},
|
err::{self, PyErr, PyResult},
|
||||||
IntoPyPointer, Py,
|
Py,
|
||||||
};
|
};
|
||||||
use crate::{ffi, AsPyPointer, PyAny, PyObject, Python, ToPyObject};
|
use crate::{ffi, AsPyPointer, PyAny, PyObject, Python, ToPyObject};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -260,7 +260,7 @@ pub(crate) fn new_from_iter<T: ToPyObject>(
|
||||||
|
|
||||||
for obj in elements {
|
for obj in elements {
|
||||||
unsafe {
|
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()))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue