From adf47c347a58acca06df08f1da3634d36d4a6434 Mon Sep 17 00:00:00 2001 From: alc Date: Thu, 6 Nov 2003 05:58:26 +0000 Subject: - 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. --- sys/kern/sys_pipe.c | 6 +----- 1 file changed, 1 insertion(+), 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); -- cgit v1.1