summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralc <alc@FreeBSD.org>2003-11-06 05:58:26 +0000
committeralc <alc@FreeBSD.org>2003-11-06 05:58:26 +0000
commitadf47c347a58acca06df08f1da3634d36d4a6434 (patch)
tree0793ee7cdaa448076fb240b476bbfe70f5b1556f
parentddec4754a22f0f3dcdd056f77b93a2516128d16d (diff)
downloadFreeBSD-src-adf47c347a58acca06df08f1da3634d36d4a6434.zip
FreeBSD-src-adf47c347a58acca06df08f1da3634d36d4a6434.tar.gz
- Delay the allocation of memory for the pipe mutex until we need it.
This avoids the need to free said memory in various error cases along the way.
-rw-r--r--sys/kern/sys_pipe.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 9aae3ef..3208e5c 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -222,13 +222,10 @@ pipe(td, uap)
struct mtx *pmtx;
int fd, error;
- pmtx = malloc(sizeof(*pmtx), M_TEMP, M_WAITOK | M_ZERO);
-
rpipe = wpipe = NULL;
if (pipe_create(&rpipe) || pipe_create(&wpipe)) {
pipeclose(rpipe);
pipeclose(wpipe);
- free(pmtx, M_TEMP);
return (ENFILE);
}
@@ -239,7 +236,6 @@ pipe(td, uap)
if (error) {
pipeclose(rpipe);
pipeclose(wpipe);
- free(pmtx, M_TEMP);
return (error);
}
/* An extra reference on `rf' has been held for us by falloc(). */
@@ -269,7 +265,6 @@ pipe(td, uap)
fdrop(rf, td);
/* rpipe has been closed by fdrop(). */
pipeclose(wpipe);
- free(pmtx, M_TEMP);
return (error);
}
/* An extra reference on `wf' has been held for us by falloc(). */
@@ -293,6 +288,7 @@ pipe(td, uap)
mac_init_pipe(rpipe);
mac_create_pipe(td->td_ucred, rpipe);
#endif
+ pmtx = malloc(sizeof(*pmtx), M_TEMP, M_WAITOK | M_ZERO);
mtx_init(pmtx, "pipe mutex", NULL, MTX_DEF | MTX_RECURSE);
rpipe->pipe_mtxp = wpipe->pipe_mtxp = pmtx;
fdrop(rf, td);
OpenPOWER on IntegriCloud