Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-37989: [Python] Plug reference leaks when creating Arrow array from Python list of dicts #40412

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/pyarrow/src/arrow/python/python_to_arrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ class PyStructConverter : public StructConverter<PyConverter, PyConverterTrait>
case KeyKind::BYTES:
return AppendDict(dict, bytes_field_names_.obj());
default:
RETURN_NOT_OK(InferKeyKind(PyDict_Items(dict)));
OwnedRef item_ref(PyDict_Items(dict));
RETURN_NOT_OK(InferKeyKind(item_ref.obj()));
if (key_kind_ == KeyKind::UNKNOWN) {
// was unable to infer the type which means that all keys are absent
return AppendEmpty();
Expand Down Expand Up @@ -1115,6 +1116,7 @@ class PyStructConverter : public StructConverter<PyConverter, PyConverterTrait>
Result<std::pair<PyObject*, PyObject*>> GetKeyValuePair(PyObject* seq, int index) {
PyObject* pair = PySequence_GetItem(seq, index);
RETURN_IF_PYERROR();
OwnedRef pair_ref(pair); // ensure reference count is decreased at scope end
if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2) {
return internal::InvalidType(pair, "was expecting tuple of (key, value) pair");
}
Expand Down
Loading