Skip to content

BUG: Fix memory leak in dtype from dict contructor #13855

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

Merged
merged 2 commits into from
Jun 28, 2019

Conversation

seberg
Copy link
Member

@seberg seberg commented Jun 27, 2019

Fixes gh-13853

@seberg seberg force-pushed the dtype-from-dict branch from c17c919 to bab94fb Compare June 27, 2019 22:46
@seberg
Copy link
Member Author

seberg commented Jun 27, 2019

Thinking about using Py_SETREF(new, NULL); goto finish; instead of that annoying duplication...

@seberg seberg force-pushed the dtype-from-dict branch from 6905112 to bab94fb Compare June 27, 2019 22:54
@seberg seberg force-pushed the dtype-from-dict branch from bab94fb to 0570cff Compare June 27, 2019 22:55
Py_XDECREF(names);
Py_XDECREF(descrs);
Py_XDECREF(offsets);
Py_XDECREF(titles);
Copy link
Member Author

@seberg seberg Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK back to this version, setref is too smart/not that nice. But this just duplicates the fail path, so could avoid that. But right now that just feels like touching more code than necessary.

Copy link
Member

@eric-wieser eric-wieser Jun 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names and fields are always null here, they're set on line 1235

Copy link
Member

@eric-wieser eric-wieser Jun 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for offsets, descrs, and titles, I'd be inclined to decref and null them on 1212, where they are last used.

Either than or line 1235, so all the nulling happens in one place. Py_CLEAR() would work to combine the null and decref, althoug is a little unusual for local variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe better. The nicer pattern would be to use the same cleanup code for success and failure path I think, which is why this unnecessary decref got in. But yeah, I can just decref it all there and think about moving things some other day

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose I could see it either way. I'll let you make the call.

@seberg
Copy link
Member Author

seberg commented Jun 28, 2019

Found that strange reference count leak we were looking for Matti ;), since it is trivial pushed a fix (no test)

@@ -32,6 +32,7 @@ npy_ctypes_check(PyTypeObject *obj)
}

ret = PyObject_IsTrue(ret_obj);
Py_DECREF(ret_obj);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a whole bunch more, I think refcount testing might be a big soon (except f2py probably), that would be awesome...

@mattip mattip merged commit ad84b69 into numpy:master Jun 28, 2019
@seberg seberg deleted the dtype-from-dict branch June 28, 2019 16:18
@charris charris modified the milestones: 1.17.0 release, 1.16.5 release Jul 14, 2019
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 18, 2019
@charris charris removed this from the 1.16.5 release milestone Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak in recarrays reappeared in 1.16.3
4 participants