Skip to content

Conversation

@vlm
Copy link
Contributor

@vlm vlm commented Oct 31, 2019

  • Leak of the output pipe file descriptors if control pipe can't be opened.
  • Leak of posix file actions memory if the control pipes can't be created.
  • Descriptors leak of unrelated tasks into spawned task (linux, win).
  • Windows code improperly inheriting the control file descriptors.
  • Windows code not checking results of the system calls.
  • A race condition in the control channel parsing on windows resulting in a potential double-close() (which can close someone else's handle).

rdar://56800263

vlm added 2 commits October 31, 2019 16:32
 * Leak of the output pipe file descriptors if control pipe can't be opened.
 * Leak of posix file actions memory if the control pipes can't be created.
 * Descriptors leak of unrelated tasks into spawned task (linux, win).
 * Windows code improperly inheriting the control file descriptors.
 * A race condition in the control channel parsing on windows resulting in
   a potential double-free.

rdar://56800263
@vlm vlm requested review from ddunbar and dmbryson as code owners October 31, 2019 23:37
@vlm
Copy link
Contributor Author

vlm commented Oct 31, 2019

@swift-ci please smoke test


// Close the child ends of the forwarded output and control pipes.
controlPipeChildEnd.close();
outputPipeChildEnd.close();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The child ends should be closed under the lock because they are potentially inheritable by other processes if we are to spawn one in a parallel thread.

std::shared_ptr<ManagedDescriptor> outputFdShared
= std::make_shared<ManagedDescriptor>(std::move(outputPipeParentEnd));
std::shared_ptr<ManagedDescriptor> controlFdShared
= std::make_shared<ManagedDescriptor>(std::move(controlPipeParentEnd));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The shared_ptrs are necessary because we disabled the copy constructor on a ManagedDescriptor, which makes it impossible to copy lambdas around, which makes it impossible to capture it in a lambda with a purpose of forwarding it further.

@vlm
Copy link
Contributor Author

vlm commented Oct 31, 2019

@gmittert if you have a chance to check the windows portion that'd be great!

@gmittert
Copy link
Contributor

gmittert commented Nov 1, 2019

@vlm Sure! Might take me a bit though, I'm out of office this week.

@vlm vlm merged commit b075db1 into swiftlang:master Nov 1, 2019
@vlm vlm deleted the fix-descriptor-leak branch November 1, 2019 21:16
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.

3 participants