Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix possible leak of return of PySequence_GetItem.#13333

Merged
NelleV merged 1 commit intomatplotlib:masterfrom
QuLogic:PySequence_GetItem-leak
Feb 2, 2019
Merged

Fix possible leak of return of PySequence_GetItem.#13333
NelleV merged 1 commit intomatplotlib:masterfrom
QuLogic:PySequence_GetItem-leak

Conversation

@QuLogic
Copy link
Copy Markdown
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
Comment thread src/_path_wrapper.cpp
return NULL;
}
codes[i] = PyBytes_AsString(item);
Py_DECREF(item);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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