summaryrefslogtreecommitdiffstats
path: root/sys/kern/sys_pipe.c
diff options
context:
space:
mode:
authormikeb <mikeb@openbsd.org>2012-05-06 09:45:26 +0000
committermikeb <mikeb@openbsd.org>2012-05-06 09:45:26 +0000
commita7f5c1f36d1cc48d8374a09127d8ba6c4bd9a516 (patch)
tree851205c8c8ba2cedabe4df7d97d490f8f4bc7d34 /sys/kern/sys_pipe.c
parentAdd a helper function to open the terminal for attach-/new-session. (diff)
downloadwireguard-openbsd-a7f5c1f36d1cc48d8374a09127d8ba6c4bd9a516.tar.xz
wireguard-openbsd-a7f5c1f36d1cc48d8374a09127d8ba6c4bd9a516.zip
take a file descriptor table lock after allocating pipe structures
and buffers; ok guenther
Diffstat (limited to 'sys/kern/sys_pipe.c')
-rw-r--r--sys/kern/sys_pipe.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 5e0058013c0..20cb0bbcb3c 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_pipe.c,v 1.62 2012/04/22 05:43:14 guenther Exp $ */
+/* $OpenBSD: sys_pipe.c,v 1.63 2012/05/06 09:45:26 mikeb Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
@@ -108,11 +108,9 @@ sys_pipe(struct proc *p, void *v, register_t *retval)
} */ *uap = v;
struct filedesc *fdp = p->p_fd;
struct file *rf, *wf;
- struct pipe *rpipe, *wpipe;
+ struct pipe *rpipe, *wpipe = NULL;
int fds[2], error;
- fdplock(fdp);
-
rpipe = pool_get(&pipe_pool, PR_WAITOK);
error = pipe_create(rpipe);
if (error != 0)
@@ -120,7 +118,9 @@ sys_pipe(struct proc *p, void *v, register_t *retval)
wpipe = pool_get(&pipe_pool, PR_WAITOK);
error = pipe_create(wpipe);
if (error != 0)
- goto free2;
+ goto free1;
+
+ fdplock(fdp);
error = falloc(p, &rf, &fds[0]);
if (error != 0)
@@ -157,11 +157,10 @@ free3:
closef(rf, p);
rpipe = NULL;
free2:
- (void)pipeclose(wpipe);
-free1:
- if (rpipe != NULL)
- (void)pipeclose(rpipe);
fdpunlock(fdp);
+free1:
+ pipeclose(wpipe);
+ pipeclose(rpipe);
return (error);
}