FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-20104: Fix memory leaks and error handling in posix spawn by pablogsal · Pull Request #5418 · python/cpython · GitHub

Repository navigation

bpo-20104: Fix memory leaks and error handling in posix spawn - #5418

Merged
gpshead merged 9 commits into
python:masterfrom
pablogsal:bpo20104
Jan 29, 2018
Merged

gpshead merged 9 commits into
python:masterfrom
pablogsal:bpo20104

Conversation

pablogsal commented Jan 29, 2018 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member Author

CC: @vadmium @gpshead

Comment thread Modules/posixmodule.c Outdated

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Put goto last?

Comment thread Modules/posixmodule.c Outdated

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Spelling: occurred

Comment thread Modules/posixmodule.c Outdated

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If this ever fails, you have an infinite loop.

file_actionsp is only initialized halfway down. In C99 I understand the goto statements above it are allowed to bypass the initialization, but they leave the pointer uninitialized.

Also, I haven’t seen any explicit mention of destroy accepting a null pointer. Did you test this? Even if it works on one platform, it seems risky to rely on it on all Posix platforms.

Comment thread Modules/posixmodule.c Outdated

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It looks to me like result will be uninitialized in the failure cases. But surely this would be obvious by testing. Am I missing something?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@vadmium Sorry, there was a commit missing here for some reason, I will amend with the latest changes.

Comment thread Modules/posixmodule.c Outdated

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

envlist could be uninitialized if there is an early failure

pablogsal force-pushed the bpo20104 branch 2 times, most recently from 2512695 to cb74d14 Compare January 29, 2018 10:14

pablogsal commented Jan 29, 2018 •
edited
Loading

Copy link
Copy Markdown
Member Author

@vadmium There was a missing commit due to a failed push. I have amended the last commit to including all the fixes. In cb74d14 you will find the correct initial implementation. Sorry for the confusion.

Comment thread Modules/posixmodule.c Outdated

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pid uninitialized again (in error case). Maybe add another goto exit.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done in 47cec89

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Also, now there is always cleanup for the result of PySequence_Fast.

pablogsal commented Jan 29, 2018 •
edited
Loading

Copy link
Copy Markdown
Member Author

@vstinner Can you take a general look at this PR (if you have the time) to check that we are not missing something else? (The Docs are not included in this PR)

gpshead left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

thanks for the cleanup!

Comment thread Modules/posixmodule.c Outdated
int err_code = posix_spawn(&pid, path->narrow, file_actionsp, NULL, argvlist, envlist);
_Py_END_SUPPRESS_IPH
if(err_code) {
PyErr_SetString(PyExc_OSError,"posix_spawn call exited");

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

"posix_spawn call failed" (it always exits)

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done in 1b75f89

Comment thread Modules/posixmodule.c Outdated

fail:
if(file_actionsp && posix_spawn_file_actions_destroy(file_actionsp)) {
PyErr_SetString(PyExc_OSError,"Error cleaning file actions object");

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The only possible error from posix_spawn_file_actions_destroy() is EINVAL if the supplied file_actionsp was invalid. That will only happen here during the "goto exit" path after a failure from posix_spawn_file_actions_init(), meaning this exception could clobber that one. I'd just leave the_destroy() call unchecked, there isn't anything we can do if it fails anyways.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done in 1b75f89

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

gpshead added skip news type-bug An unexpected behavior, bug, or error labels Jan 29, 2018

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again

Copy link
Copy Markdown

Thanks for making the requested changes!

@gpshead: please review the changes made to this pull request.

Comment thread Modules/posixmodule.c
* https://android-review.googlesource.com/c/platform/bionic/+/504842
**/
#ifndef __ANDROID__
#define HAVE_POSIX_SPAWN 1

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

just for my own info, why do you remove this condition? you won't support all the versions of Android... is it right?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The check is done now in the configuration phase and it will be automatically detected if the system has this function.

gpshead merged commit 0cd6bca into python:master Jan 29, 2018
pablogsal deleted the bpo20104 branch January 29, 2018 21:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL