Skip to content

Commit

Permalink
util: Close output if exec fails
Browse files Browse the repository at this point in the history
  • Loading branch information
dasJ committed Nov 22, 2016
1 parent 4411dfd commit 34494b0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/zfs-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int execute(char *command, char needOutput, char **output, char *param[]) {
char *linebuffer;
size_t size;
int nRead;
int fd;

// Execute
if (needOutput == 1) {
Expand All @@ -33,13 +34,15 @@ int execute(char *command, char needOutput, char **output, char *param[]) {
close(2);
if (needOutput == 1) {
close(pip[0]);
if (dup(pip[1]) < 0) {
fd = dup(pip[1]);
if (fd < 0) {
perror("Can not duplicate pipe\n");
close(pip[1]);
}
}
// Execute
execv(command, param);
close(fd);
exit(254);
} else if (pid < 0) {
perror("Can not fork\n");
Expand Down

0 comments on commit 34494b0

Please sign in to comment.