summaryrefslogtreecommitdiffstats
path: root/sys/compat/linux/linux_file.c
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2017-03-19 10:32:39 +0000
committertrasz <trasz@FreeBSD.org>2017-03-19 10:32:39 +0000
commit29b3a1a054eda4b49e35723c6f82249edc22b267 (patch)
tree807c476b01ae6886219a295568a1124ad64b9bf6 /sys/compat/linux/linux_file.c
parent7accacf9dd80d5c5438c3a6b860514b72a3d8f87 (diff)
downloadFreeBSD-src-29b3a1a054eda4b49e35723c6f82249edc22b267.zip
FreeBSD-src-29b3a1a054eda4b49e35723c6f82249edc22b267.tar.gz
MFC r313283:
Fix linux_pipe() and linux_pipe2() to close file descriptors on copyout error.
Diffstat (limited to 'sys/compat/linux/linux_file.c')
-rw-r--r--sys/compat/linux/linux_file.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index 5fb41c4..dfc7f7c 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1629,11 +1629,16 @@ linux_pipe(struct thread *td, struct linux_pipe_args *args)
#endif
error = kern_pipe(td, fildes, 0, NULL, NULL);
- if (error)
+ if (error != 0)
return (error);
- /* XXX: Close descriptors on error. */
- return (copyout(fildes, args->pipefds, sizeof(fildes)));
+ error = copyout(fildes, args->pipefds, sizeof(fildes));
+ if (error != 0) {
+ (void)kern_close(td, fildes[0]);
+ (void)kern_close(td, fildes[1]);
+ }
+
+ return (error);
}
int
@@ -1656,11 +1661,16 @@ linux_pipe2(struct thread *td, struct linux_pipe2_args *args)
if ((args->flags & LINUX_O_CLOEXEC) != 0)
flags |= O_CLOEXEC;
error = kern_pipe(td, fildes, flags, NULL, NULL);
- if (error)
+ if (error != 0)
return (error);
- /* XXX: Close descriptors on error. */
- return (copyout(fildes, args->pipefds, sizeof(fildes)));
+ error = copyout(fildes, args->pipefds, sizeof(fildes));
+ if (error != 0) {
+ (void)kern_close(td, fildes[0]);
+ (void)kern_close(td, fildes[1]);
+ }
+
+ return (error);
}
int
OpenPOWER on IntegriCloud