From: wessels <> Date: Fri, 1 Dec 2000 03:08:47 +0000 (+0000) Subject: storeDirWriteCleanLogs() could abort the procedure if file_open() X-Git-Tag: SQUID_3_0_PRE1~1755 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81928dfece6815198ce3107c28e59b3b73f63bd1;p=thirdparty%2Fsquid.git storeDirWriteCleanLogs() could abort the procedure if file_open() fails, leaking various structures including repl walkers. --- diff --git a/src/fs/aufs/store_dir_aufs.cc b/src/fs/aufs/store_dir_aufs.cc index da1169045c..999187f830 100644 --- a/src/fs/aufs/store_dir_aufs.cc +++ b/src/fs/aufs/store_dir_aufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.cc,v 1.17 2000/11/30 20:07:32 wessels Exp $ + * $Id: store_dir_aufs.cc,v 1.18 2000/11/30 20:08:47 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -971,6 +971,11 @@ storeAufsDirWriteCleanStart(SwapDir * sd) struct stat sb; sd->log.clean.write = NULL; sd->log.clean.state = NULL; + state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); + if (state->fd < 0) { + xfree(state); + return -1; + } state->cur = xstrdup(storeAufsDirSwapLogFile(sd, NULL)); state->new = xstrdup(storeAufsDirSwapLogFile(sd, ".clean")); state->cln = xstrdup(storeAufsDirSwapLogFile(sd, ".last-clean")); @@ -979,9 +984,6 @@ storeAufsDirWriteCleanStart(SwapDir * sd) state->walker = sd->repl->WalkInit(sd->repl); unlink(state->new); unlink(state->cln); - state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); - if (state->fd < 0) - return -1; debug(20, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n", state->new, state->fd); #if HAVE_FCHMOD diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index 29ab53e349..1c1943e950 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.9 2000/11/02 18:34:48 wessels Exp $ + * $Id: store_dir_coss.cc,v 1.10 2000/11/30 20:08:50 wessels Exp $ * * DEBUG: section 81 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -467,6 +467,11 @@ storeCossDirWriteCleanStart(SwapDir * sd) CossInfo *cs = (CossInfo *) sd->fsdata; struct _clean_state *state = xcalloc(1, sizeof(*state)); struct stat sb; + state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); + if (state->fd < 0) { + xfree(state); + return -1; + } sd->log.clean.write = NULL; sd->log.clean.state = NULL; state->cur = xstrdup(storeCossDirSwapLogFile(sd, NULL)); @@ -476,9 +481,6 @@ storeCossDirWriteCleanStart(SwapDir * sd) state->outbuf_offset = 0; unlink(state->new); unlink(state->cln); - state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); - if (state->fd < 0) - return -1; state->current = cs->index.tail; debug(20, 3) ("storeCOssDirWriteCleanLogs: opened %s, FD %d\n", state->new, state->fd); diff --git a/src/fs/diskd/store_dir_diskd.cc b/src/fs/diskd/store_dir_diskd.cc index 427b309d91..c0b36eadba 100644 --- a/src/fs/diskd/store_dir_diskd.cc +++ b/src/fs/diskd/store_dir_diskd.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_diskd.cc,v 1.25 2000/11/30 20:07:32 wessels Exp $ + * $Id: store_dir_diskd.cc,v 1.26 2000/11/30 20:08:50 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -1162,6 +1162,11 @@ storeDiskdDirWriteCleanStart(SwapDir * sd) struct stat sb; sd->log.clean.write = NULL; sd->log.clean.state = NULL; + state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); + if (state->fd < 0) { + xfree(state); + return -1; + } state->cur = xstrdup(storeDiskdDirSwapLogFile(sd, NULL)); state->new = xstrdup(storeDiskdDirSwapLogFile(sd, ".clean")); state->cln = xstrdup(storeDiskdDirSwapLogFile(sd, ".last-clean")); diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 945ff7e13d..cf80edace6 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.15 2000/11/30 20:07:33 wessels Exp $ + * $Id: store_dir_ufs.cc,v 1.16 2000/11/30 20:08:51 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -969,6 +969,11 @@ storeUfsDirWriteCleanStart(SwapDir * sd) struct stat sb; sd->log.clean.write = NULL; sd->log.clean.state = NULL; + state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); + if (state->fd < 0) { + xfree(state); + return -1; + } state->cur = xstrdup(storeUfsDirSwapLogFile(sd, NULL)); state->new = xstrdup(storeUfsDirSwapLogFile(sd, ".clean")); state->cln = xstrdup(storeUfsDirSwapLogFile(sd, ".last-clean")); @@ -977,9 +982,6 @@ storeUfsDirWriteCleanStart(SwapDir * sd) state->walker = sd->repl->WalkInit(sd->repl); unlink(state->new); unlink(state->cln); - state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC); - if (state->fd < 0) - return -1; /* state not free'd - possible leak */ debug(20, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n", state->new, state->fd); #if HAVE_FCHMOD