Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix possible leak of return of PySequence_GetItem. #13333

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 1 commit into from
Feb 2, 2019

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jan 31, 2019

PR Summary

PySequence_GetItem returns a new reference, which we should decrement.

Note: Technically, the string (from PyBytes_AsString) requires the object to be ref'd, but we know it won't get GC'd because there's a ref by the containing object, and doing it early means we don't have to worry about error handling.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • [N/A] New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@QuLogic QuLogic added this to the v3.0.3 milestone Jan 31, 2019
@@ -727,6 +727,7 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
return NULL;
}
codes[i] = PyBytes_AsString(item);
Py_DECREF(item);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just change the PyArg_ParseTuple call to use a (yyyyy) format for parsing the codes argument instead?

Copy link
Member

Choose a reason for hiding this comment

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

I am 50/50 on that. It lets python do more of the work, but is also a bigger change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think all of our callers pass the right length lists, but as I'm targeting 3.0.3 with this, I'm not sure if it's quite as safe to be backporting that version.

Copy link
Contributor

Choose a reason for hiding this comment

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

But we already error out a few lines above if the length is not 5.
Anyways I don't want to insist too much on this, if you don't want to make the bigger change that's fine with me too.

Copy link
Member

@NelleV NelleV left a comment

Choose a reason for hiding this comment

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

Thanks @QuLogic !

@NelleV NelleV merged commit 8d62769 into matplotlib:master Feb 2, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 2, 2019
@QuLogic QuLogic deleted the PySequence_GetItem-leak branch February 2, 2019 07:29
timhoffm added a commit that referenced this pull request Feb 2, 2019
…333-on-v3.0.x

Backport PR #13333 on branch v3.0.x (Fix possible leak of return of PySequence_GetItem.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.