summaryrefslogtreecommitdiff
path: root/libs/androidfw
diff options
context:
space:
mode:
authorPeter Collingbourne <pcc@google.com>2021-04-15 21:42:37 -0700
committerPeter Collingbourne <pcc@google.com>2021-04-15 21:47:07 -0700
commitb3982fc8be5cac77e572fc540addd9d489b42698 (patch)
tree458098b55a29bd29c5b36ca8b8ab12871014eafd /libs/androidfw
parent6b5e6bba9b0eb9c8e42fa16899c7bc738a51c5b0 (diff)
Fix two problems in the ExecuteBinary function.
- If the process exits abnormally then we will leak the stdout and stderr FDs. Fix it by closing the FDs before returning. - If another child process exits then we will incorrectly return the result from that process instead of waiting for our child. Fix it by using waitpid instead of wait. Change-Id: I8974d5e4bd33f264cd2d364f55a60f1f5cb7eb1a
Diffstat (limited to 'libs/androidfw')
-rw-r--r--libs/androidfw/PosixUtils.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/libs/androidfw/PosixUtils.cpp b/libs/androidfw/PosixUtils.cpp
index f1ab1493012a..4ec525a01da5 100644
--- a/libs/androidfw/PosixUtils.cpp
+++ b/libs/androidfw/PosixUtils.cpp
@@ -72,7 +72,8 @@ std::unique_ptr<ProcResult> ExecuteBinary(const std::vector<std::string>& argv)
argv0[i] = argv[i].c_str();
}
argv0[argv.size()] = nullptr;
- switch (fork()) {
+ int pid = fork();
+ switch (pid) {
case -1: // error
free(argv0);
PLOG(ERROR) << "fork";
@@ -104,8 +105,10 @@ std::unique_ptr<ProcResult> ExecuteBinary(const std::vector<std::string>& argv)
close(stdout[1]);
close(stderr[1]);
int status;
- wait(&status);
+ waitpid(pid, &status, 0);
if (!WIFEXITED(status)) {
+ close(stdout[0]);
+ close(stderr[0]);
return nullptr;
}
std::unique_ptr<ProcResult> result(new ProcResult());