8289643: File descriptor leak with ProcessBuilder.startPipeline

Reviewed-by: alanb, jpai, lancea
This commit is contained in:
Roger Riggs 2022-07-21 18:57:23 +00:00
parent 7ec0132ad3
commit 620c8a045f
2 changed files with 144 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1296,6 +1296,10 @@ public final class ProcessBuilder
redirects[1] = new RedirectPipeImpl(); // placeholder for new output
}
processes.add(builder.start(redirects));
if (prevOutput instanceof RedirectPipeImpl redir) {
// Wrap the fd so it can be closed
new Process.PipeInputStream(redir.getFd()).close();
}
prevOutput = redirects[1];
}
} catch (Exception ex) {