From: wessels <> Date: Sat, 20 Jul 1996 09:16:49 +0000 (+0000) Subject: -Changed comm_write() to free/give up memory after the write has been X-Git-Tag: SQUID_3_0_PRE1~6020 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9864ee446014bba45d1b4c699563dd35c6c28997;p=thirdparty%2Fsquid.git -Changed comm_write() to free/give up memory after the write has been called. Removed most of the 'page_ptr' cruft in other data strucutres. -Combined hierarchy.log into access.log -Changed some stray comm_write()'s into icpSendERROR()'s --- diff --git a/src/comm.cc b/src/comm.cc index d2a09d2cc4..9a7e523e9a 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.40 1996/07/19 17:37:39 wessels Exp $ + * $Id: comm.cc,v 1.41 1996/07/20 03:16:49 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -129,6 +129,7 @@ struct _RWStateData { rw_complete_handler *handler; void *handler_data; int handle_immed; + void (*free)(void *); }; /* GLOBAL */ @@ -143,6 +144,7 @@ static int examine_select _PARAMS((fd_set *, fd_set *, fd_set *)); static void commSetNoLinger _PARAMS((int)); static void comm_select_incoming _PARAMS((void)); static int commBind _PARAMS((int s, struct in_addr, u_short port)); +static void RWStateFree _PARAMS((int fd, RWStateData *, int code)); #ifdef TCP_NODELAY static void commSetTcpNoDelay _PARAMS((int)); #endif @@ -150,28 +152,53 @@ static void commSetTcpNoDelay _PARAMS((int)); static int *fd_lifetime = NULL; static struct timeval zero_tv; +static void RWStateFree(fd, RWState, code) + int fd; + RWStateData *RWState; + int code; +{ + rw_complete_handler *callback = NULL; + if (RWState == NULL) + return; + if (RWState->free) { + RWState->free(RWState->buf); + RWState->buf = NULL; + } + callback = RWState->handler; + RWState->handler = NULL; + if (callback) { + callback(fd, + RWState->buf, + RWState->offset, + code, + RWState->handler_data); + } + safe_free(RWState); +} + /* Return the local port associated with fd. */ u_short comm_local_port(fd) int fd; { struct sockaddr_in addr; int addr_len = 0; + FD_ENTRY *fde = &fd_table[fd]; /* If the fd is closed already, just return */ - if (!fd_table[fd].openned) { + if (!fde->openned) { debug(5, 0, "comm_local_port: FD %d has been closed.\n", fd); return 0; } - if (fd_table[fd].local_port) - return fd_table[fd].local_port; + if (fde->local_port) + return fde->local_port; addr_len = sizeof(addr); if (getsockname(fd, (struct sockaddr *) &addr, &addr_len)) { debug(5, 1, "comm_local_port: Failed to retrieve TCP/UDP port number for socket: FD %d: %s\n", fd, xstrerror()); return 0; } debug(5, 6, "comm_local_port: FD %d: sockaddr %u.\n", fd, addr.sin_addr.s_addr); - fd_table[fd].local_port = ntohs(addr.sin_port); - return fd_table[fd].local_port; + fde->local_port = ntohs(addr.sin_port); + return fde->local_port; } static int commBind(s, in_addr, port) @@ -450,32 +477,33 @@ int comm_accept(fd, peer, me) return sock; } -int comm_close(fd) +void comm_close(fd) int fd; { FD_ENTRY *conn = NULL; struct close_handler *ch = NULL; debug(5, 5, "comm_close: FD %d\n", fd); - if (fd < 0) - return -1; + if (fd < 0 || fd >= FD_SETSIZE) + return; + conn = &fd_table[fd]; + if (!conn->openned) + return; if (fdstatGetType(fd) == FD_FILE) { debug(5, 0, "FD %d: Someone called comm_close() on a File\n", fd); fatal_dump(NULL); } - conn = &fd_table[fd]; - safe_free(conn->rstate); - safe_free(conn->wstate); + conn->openned = 0; + RWStateFree(fd, conn->rstate, COMM_ERROR); + RWStateFree(fd, conn->wstate, COMM_ERROR); comm_set_fd_lifetime(fd, -1); /* invalidate the lifetime */ - /* update fdstat */ - fdstat_close(fd); - /* Call close handlers */ - while ((ch = conn->close_handler)) { + fdstat_close(fd); /* update fdstat */ + while ((ch = conn->close_handler)) { /* Call close handlers */ conn->close_handler = ch->next; ch->handler(fd, ch->data); safe_free(ch); } memset(conn, '\0', sizeof(FD_ENTRY)); - return close(fd); + close(fd); } /* use to clean up fdtable when socket is closed without @@ -484,8 +512,8 @@ int comm_cleanup_fd_entry(fd) int fd; { FD_ENTRY *conn = &fd_table[fd]; - safe_free(conn->rstate); - safe_free(conn->wstate); + RWStateFree(fd, conn->rstate, COMM_ERROR); + RWStateFree(fd, conn->wstate, COMM_ERROR); memset(conn, 0, sizeof(FD_ENTRY)); return 0; } @@ -1114,6 +1142,7 @@ static void checkLifetimes() { int fd; time_t lft; + FD_ENTRY *fde = NULL; int (*func) () = NULL; @@ -1123,28 +1152,29 @@ static void checkLifetimes() if (lft > squid_curtime) continue; debug(5, 5, "checkLifetimes: FD %d Expired\n", fd); - if ((func = fd_table[fd].lifetime_handler)) { + fde = &fd_table[fd]; + if ((func = fde->lifetime_handler)) { debug(5, 5, "checkLifetimes: FD %d: Calling lifetime handler\n", fd); - func(fd, fd_table[fd].lifetime_data); - fd_table[fd].lifetime_handler = NULL; - } else if ((func = fd_table[fd].read_handler)) { + func(fd, fde->lifetime_data); + fde->lifetime_handler = NULL; + } else if ((func = fde->read_handler)) { debug(5, 5, "checkLifetimes: FD %d: Calling read handler\n", fd); - func(fd, fd_table[fd].read_data); - fd_table[fd].read_handler = NULL; - } else if ((func = fd_table[fd].read_handler)) { + func(fd, fde->read_data); + fde->read_handler = NULL; + } else if ((func = fde->read_handler)) { debug(5, 5, "checkLifetimes: FD %d: Calling read handler\n", fd); - func(fd, fd_table[fd].read_data); - fd_table[fd].read_handler = NULL; - } else if ((func = fd_table[fd].write_handler)) { + func(fd, fde->read_data); + fde->read_handler = NULL; + } else if ((func = fde->write_handler)) { debug(5, 5, "checkLifetimes: FD %d: Calling write handler\n", fd); - func(fd, fd_table[fd].write_data); - fd_table[fd].write_handler = NULL; + func(fd, fde->write_data); + fde->write_handler = NULL; } else { debug(5, 5, "checkLifetimes: FD %d: No handlers, calling comm_close()\n", fd); comm_close(fd); comm_cleanup_fd_entry(fd); } - if (fd_table[fd].openned) { + if (fde->openned) { /* still opened */ debug(5, 5, "checkLifetimes: FD %d: Forcing comm_close()\n", fd); comm_close(fd); @@ -1193,30 +1223,20 @@ static int commHandleRead(fd, state) debug(5, 5, "commHandleRead: FD %d: read %d bytes\n", fd, len); if (len <= 0) { - switch (errno) { -#if EAGAIN != EWOULDBLOCK - case EAGAIN: -#endif - case EWOULDBLOCK: + if (errno == EWOULDBLOCK || errno == EAGAIN) { /* reschedule self */ comm_set_select_handler(fd, COMM_SELECT_READ, (PF) commHandleRead, state); return COMM_OK; - default: + } else { /* Len == 0 means connection closed; otherwise would not have been * called by comm_select(). */ debug(5, len == 0 ? 2 : 1, "commHandleRead: FD %d: read failure: %s\n", fd, len == 0 ? "connection closed" : xstrerror()); fd_table[fd].rstate = NULL; /* The handler may issue a new read */ - /* Notify caller that we failed */ - state->handler(fd, - state->buf, - state->offset, - COMM_ERROR, - state->handler_data); - safe_free(state); + RWStateFree(fd, state, COMM_ERROR); return COMM_ERROR; } } @@ -1225,12 +1245,7 @@ static int commHandleRead(fd, state) /* Call handler if we have read enough */ if (state->offset >= state->size || state->handle_immed) { fd_table[fd].rstate = NULL; /* The handler may issue a new read */ - state->handler(fd, - state->buf, - state->offset, - COMM_OK, - state->handler_data); - safe_free(state); + RWStateFree(fd, state, COMM_OK); } else { /* Reschedule until we are done */ comm_set_select_handler(fd, @@ -1271,6 +1286,7 @@ void comm_read(fd, buf, size, timeout, immed, handler, handler_data) state->handle_immed = immed; state->time = squid_curtime; state->handler_data = handler_data; + state->free = NULL; comm_set_select_handler(fd, COMM_SELECT_READ, (PF) commHandleRead, @@ -1297,45 +1313,22 @@ static void commHandleWrite(fd, state) if (nleft != 0) debug(5, 2, "commHandleWrite: FD %d: write failure: connection closed with %d bytes remaining.\n", fd, nleft); fd_table[fd].wstate = NULL; - if (state->handler) - state->handler(fd, - state->buf, - state->offset, - nleft ? COMM_ERROR : COMM_OK, - state->handler_data); - else - xfree(state->buf); - safe_free(state); - return; + RWStateFree(fd, state, nleft ? COMM_ERROR : COMM_OK); } else if (len < 0) { /* An error */ if (errno == EWOULDBLOCK || errno == EAGAIN) { - /* XXX: Re-install the handler rather than giving up. I hope - * this doesn't freeze this socket due to some random OS bug - * returning EWOULDBLOCK indefinitely. Ought to maintain a - * retry count in state? */ debug(5, 10, "commHandleWrite: FD %d: write failure: %s.\n", fd, xstrerror()); comm_set_select_handler(fd, COMM_SELECT_WRITE, (PF) commHandleWrite, state); - return; + } else { + debug(5, 2, "commHandleWrite: FD %d: write failure: %s.\n", + fd, xstrerror()); + fd_table[fd].wstate = NULL; + RWStateFree(fd, state, COMM_ERROR); } - debug(5, 2, "commHandleWrite: FD %d: write failure: %s.\n", - fd, xstrerror()); - /* Notify caller that we failed */ - fd_table[fd].wstate = NULL; - if (state->handler) - state->handler(fd, - state->buf, - state->offset, - COMM_ERROR, - state->handler_data); - else - xfree(state->buf); - safe_free(state); - return; } else { /* A successful write, continue */ state->offset += len; @@ -1345,19 +1338,10 @@ static void commHandleWrite(fd, state) COMM_SELECT_WRITE, (PF) commHandleWrite, state); - return; + } else { + fd_table[fd].wstate = NULL; + RWStateFree(fd, state, COMM_OK); } - fd_table[fd].wstate = NULL; - /* Notify caller that the write is complete */ - if (state->handler) - state->handler(fd, - state->buf, - state->offset, - COMM_OK, - state->handler_data); - else - xfree(state->buf); - safe_free(state); } } @@ -1365,13 +1349,14 @@ static void commHandleWrite(fd, state) /* Select for Writing on FD, until SIZE bytes are sent. Call * * HANDLER when complete. */ -void comm_write(fd, buf, size, timeout, handler, handler_data) +void comm_write(fd, buf, size, timeout, handler, handler_data, free) int fd; char *buf; int size; int timeout; rw_complete_handler *handler; void *handler_data; + void (*free)(void *); { RWStateData *state = NULL; @@ -1380,7 +1365,7 @@ void comm_write(fd, buf, size, timeout, handler, handler_data) if (fd_table[fd].wstate) { debug(5, 1, "comm_write: WARNING! FD %d: A comm_write is already active.\n", fd); - safe_free(fd_table[fd].wstate); + RWStateFree(fd, fd_table[fd].wstate, COMM_ERROR); } state = xcalloc(1, sizeof(RWStateData)); state->buf = buf; @@ -1390,6 +1375,7 @@ void comm_write(fd, buf, size, timeout, handler, handler_data) state->timeout = timeout; state->time = squid_curtime; state->handler_data = handler_data; + state->free = free; comm_set_select_handler(fd, COMM_SELECT_WRITE, (PF) commHandleWrite, diff --git a/src/ftp.cc b/src/ftp.cc index 890e00b77e..d14f8d802d 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.45 1996/07/19 17:38:36 wessels Exp $ + * $Id: ftp.cc,v 1.46 1996/07/20 03:16:50 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -121,9 +121,6 @@ typedef struct _Ftpdata { char password[MAX_URL]; char *reply_hdr; int ftp_fd; - char *icp_page_ptr; /* Used to send proxy-http request: - * put_free_8k_page(me) if the lifetime - * expires */ int got_marker; /* denotes end of successful request */ int reply_hdr_state; int authenticated; /* This ftp request is authenticated */ @@ -158,10 +155,6 @@ static int ftpStateFree(fd, ftpState) put_free_8k_page(ftpState->reply_hdr); ftpState->reply_hdr = NULL; } - if (ftpState->icp_page_ptr) { - put_free_8k_page(ftpState->icp_page_ptr); - ftpState->icp_page_ptr = NULL; - } requestUnlink(ftpState->request); xfree(ftpState); return 0; @@ -343,10 +336,10 @@ int ftpReadReply(fd, data) return 0; } errno = 0; - IOStats.Ftp.reads++; len = read(fd, buf, SQUID_TCP_SO_RCVBUF); debug(9, 5, "ftpReadReply: FD %d, Read %d bytes\n", fd, len); if (len > 0) { + IOStats.Ftp.reads++; for (clen = len - 1, bin = 0; clen; bin++) clen >>= 1; IOStats.Ftp.read_hist[bin]++; @@ -444,8 +437,6 @@ void ftpSendComplete(fd, buf, size, errflag, data) put_free_8k_page(buf); /* Allocated by ftpSendRequest. */ buf = NULL; } - ftpState->icp_page_ptr = NULL; /* So lifetime expire doesn't re-free */ - if (errflag) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); comm_close(fd); @@ -501,7 +492,6 @@ void ftpSendRequest(fd, data) buflen = strlen(data->request->urlpath) + 256; buf = (char *) get_free_8k_page(); - data->icp_page_ptr = buf; memset(buf, '\0', buflen); path = data->request->urlpath; @@ -557,7 +547,8 @@ void ftpSendRequest(fd, data) strlen(buf), 30, ftpSendComplete, - (void *) data); + (void *) data, + put_free_8k_page); } void ftpConnInProgress(fd, data) diff --git a/src/gopher.cc b/src/gopher.cc index e8308f8fdb..faaaaa2c3e 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,5 +1,5 @@ /* - * $Id: gopher.cc,v 1.34 1996/07/19 17:38:37 wessels Exp $ + * $Id: gopher.cc,v 1.35 1996/07/20 03:16:50 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -156,7 +156,6 @@ typedef struct gopher_ds { int cso_recno; int len; char *buf; /* pts to a 4k page */ - char *icp_page_ptr; /* Pts to gopherStart buffer that needs to be freed */ } GopherData; GopherData *CreateGopherData(); @@ -669,8 +668,6 @@ int gopherReadReplyTimeout(fd, data) entry = data->entry; debug(10, 4, "GopherReadReplyTimeout: Timeout on %d\n url: %s\n", fd, entry->url); squid_error_entry(entry, ERR_READ_TIMEOUT, NULL); - if (data->icp_page_ptr) - put_free_4k_page(data->icp_page_ptr); comm_close(fd); return 0; } @@ -684,8 +681,6 @@ void gopherLifetimeExpire(fd, data) entry = data->entry; debug(10, 4, "gopherLifeTimeExpire: FD %d: \n", fd, entry->url); squid_error_entry(entry, ERR_LIFETIME_EXP, NULL); - if (data->icp_page_ptr) - put_free_4k_page(data->icp_page_ptr); comm_set_select_handler(fd, COMM_SELECT_READ | COMM_SELECT_WRITE, 0, @@ -899,7 +894,6 @@ void gopherSendComplete(fd, buf, size, errflag, data) if (buf) put_free_4k_page(buf); /* Allocated by gopherSendRequest. */ - gopherState->icp_page_ptr = NULL; } /* This will be called when connect completes. Write request. */ @@ -911,8 +905,6 @@ void gopherSendRequest(fd, data) LOCAL_ARRAY(char, query, MAX_URL); char *buf = get_free_4k_page(); - data->icp_page_ptr = buf; - if (data->type_id == GOPHER_CSO) { sscanf(data->request, "?%s", query); len = strlen(query) + 15; @@ -935,7 +927,8 @@ void gopherSendRequest(fd, data) len, 30, gopherSendComplete, - (void *) data); + (void *) data, + put_free_4k_page); if (BIT_TEST(data->entry->flag, CACHABLE)) storeSetPublicKey(data->entry); /* Make it public */ } diff --git a/src/http.cc b/src/http.cc index da70118f63..4ea4d8f5ba 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.63 1996/07/19 17:38:38 wessels Exp $ + * $Id: http.cc,v 1.64 1996/07/20 03:16:51 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -139,12 +139,6 @@ static int httpStateFree(fd, httpState) put_free_8k_page(httpState->reply_hdr); httpState->reply_hdr = NULL; } - if (httpState->reqbuf && httpState->buf_type == BUF_TYPE_8K) { - put_free_8k_page(httpState->reqbuf); - httpState->reqbuf = NULL; - } else { - safe_free(httpState->reqbuf) - } requestUnlink(httpState->request); xfree(httpState); return 0; @@ -445,11 +439,11 @@ static void httpReadReply(fd, httpState) return; } errno = 0; - IOStats.Http.reads++; len = read(fd, buf, SQUID_TCP_SO_RCVBUF); debug(11, 5, "httpReadReply: FD %d: len %d.\n", fd, len); comm_set_fd_lifetime(fd, 86400); /* extend after good read */ if (len > 0) { + IOStats.Http.reads++; for (clen = len - 1, bin = 0; clen; bin++) clen >>= 1; IOStats.Http.read_hist[bin]++; @@ -529,13 +523,6 @@ static void httpSendComplete(fd, buf, size, errflag, data) debug(11, 5, "httpSendComplete: FD %d: size %d: errflag %d.\n", fd, size, errflag); - if (httpState->reqbuf && httpState->buf_type == BUF_TYPE_8K) { - put_free_8k_page(httpState->reqbuf); - httpState->reqbuf = NULL; - } else { - safe_free(httpState->reqbuf); - } - if (errflag) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); comm_close(fd); @@ -572,6 +559,7 @@ static void httpSendRequest(fd, httpState) int cfd = -1; request_t *req = httpState->request; char *Method = RequestMethodStr[req->method]; + int buftype = 0; debug(11, 5, "httpSendRequest: FD %d: httpState %p.\n", fd, httpState); buflen = strlen(Method) + strlen(req->urlpath); @@ -586,14 +574,13 @@ static void httpSendRequest(fd, httpState) } } if (buflen < DISK_PAGE_SIZE) { - httpState->reqbuf = get_free_8k_page(); - memset(httpState->reqbuf, '\0', buflen); - httpState->buf_type = BUF_TYPE_8K; + buf = get_free_8k_page(); + memset(buf, '\0', buflen); + buftype = BUF_TYPE_8K; } else { - httpState->reqbuf = xcalloc(buflen, 1); - httpState->buf_type = BUF_TYPE_MALLOC; + buf = xcalloc(buflen, 1); + buftype = BUF_TYPE_MALLOC; } - buf = httpState->reqbuf; sprintf(buf, "%s %s HTTP/1.0\r\n", Method, @@ -647,7 +634,8 @@ static void httpSendRequest(fd, httpState) len, 30, httpSendComplete, - httpState); + httpState, + buftype == BUF_TYPE_8K ? put_free_8k_page : xfree); } static void httpConnInProgress(fd, httpState) diff --git a/src/ident.cc b/src/ident.cc index ec1c2bc1f1..14330c0ffa 100644 --- a/src/ident.cc +++ b/src/ident.cc @@ -1,5 +1,5 @@ /* - * $Id: ident.cc,v 1.5 1996/07/18 20:27:04 wessels Exp $ + * $Id: ident.cc,v 1.6 1996/07/20 03:16:52 wessels Exp $ * * DEBUG: section 31 Ident (RFC 931) * AUTHOR: Duane Wessels @@ -83,7 +83,8 @@ void identStart(sock, icpState) strlen(reqbuf), 5, /* timeout */ identRequestComplete, - (void *) icpState); + (void *) icpState, + NULL); comm_set_select_handler(sock, COMM_SELECT_READ, (PF) identReadReply, diff --git a/src/ipcache.cc b/src/ipcache.cc index d3fe3a828a..725a0e3721 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -1,5 +1,5 @@ /* - * $Id: ipcache.cc,v 1.34 1996/07/19 17:34:45 wessels Exp $ + * $Id: ipcache.cc,v 1.35 1996/07/20 03:16:53 wessels Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -1014,7 +1014,8 @@ static void dnsDispatch(dns, i) strlen(buf), 0, /* timeout */ NULL, /* Handler */ - NULL); /* Handler-data */ + NULL, /* Handler-data */ + xfree); debug(14, 5, "dnsDispatch: Request sent to DNS server #%d.\n", dns->id); dns->dispatch_time = current_time; @@ -1289,7 +1290,8 @@ void ipcacheShutdownServers() strlen(shutdown), 0, /* timeout */ NULL, /* Handler */ - NULL); /* Handler-data */ + NULL, /* Handler-data */ + xfree); dnsData->flags |= DNS_FLAG_CLOSING; } } diff --git a/src/neighbors.cc b/src/neighbors.cc index 7d9c45da1a..4ec1be4d18 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,5 +1,5 @@ /* - * $Id: neighbors.cc,v 1.32 1996/07/19 17:35:23 wessels Exp $ + * $Id: neighbors.cc,v 1.33 1996/07/20 03:16:53 wessels Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -182,6 +182,8 @@ void hierarchy_log_append(entry, code, timeout, cache_host) code = HIER_MAX; if (mem) mem->hierarchy_code = code; + if (mem && cache_host) + mem->hierarchy_host = xstrdup(cache_host); if (emulate_httpd_log) { if (squid_curtime != last_time) { diff --git a/src/redirect.cc b/src/redirect.cc index 575d0e3c2e..675df71b2f 100644 --- a/src/redirect.cc +++ b/src/redirect.cc @@ -1,5 +1,5 @@ /* - * $Id: redirect.cc,v 1.5 1996/07/18 20:27:07 wessels Exp $ + * $Id: redirect.cc,v 1.6 1996/07/20 03:16:54 wessels Exp $ * * DEBUG: section 29 Redirector * AUTHOR: Duane Wessels @@ -269,7 +269,8 @@ static void redirectDispatch(redirect, r) len, 0, /* timeout */ NULL, /* Handler */ - NULL); /* Handler-data */ + NULL, /* Handler-data */ + xfree); debug(29, 5, "redirectDispatch: Request sent to Redirector #%d, %d bytes\n", redirect->index + 1, len); RedirectStats.use_hist[redirect->index]++; diff --git a/src/squid.h b/src/squid.h index 5c2d367f54..553ae11994 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.29 1996/07/19 17:38:38 wessels Exp $ + * $Id: squid.h,v 1.30 1996/07/20 03:16:54 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -199,7 +199,7 @@ typedef unsigned long u_num32; #endif #define NUM32LEN sizeof(num32) /* this should always be 4 */ -#if MALLOC_GUARD +#if PURIFY #define LOCAL_ARRAY(type,name,size) \ static type *local_##name=NULL; \ type *name = local_##name ? local_##name : \ diff --git a/src/ssl.cc b/src/ssl.cc index 5f1a50b493..0299717174 100644 --- a/src/ssl.cc +++ b/src/ssl.cc @@ -1,6 +1,6 @@ /* - * $Id: ssl.cc,v 1.6 1996/07/18 20:27:09 wessels Exp $ + * $Id: ssl.cc,v 1.7 1996/07/20 03:16:55 wessels Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -339,7 +339,8 @@ static void sslConnInProgress(fd, sslState) strlen(buf), 30, sslErrorComplete, - sslState); + sslState, + xfree); return; } } @@ -369,7 +370,8 @@ static int sslConnect(fd, hp, sslState) strlen(buf), 30, sslErrorComplete, - (void *) sslState); + (void *) sslState, + xfree); return COMM_ERROR; } debug(26, 5, "sslConnect: client=%d server=%d\n", @@ -402,7 +404,8 @@ static int sslConnect(fd, hp, sslState) strlen(buf), 30, sslErrorComplete, - (void *) sslState); + (void *) sslState, + xfree); return COMM_ERROR; } else { debug(26, 5, "sslConnect: conn %d EINPROGRESS\n", fd); @@ -448,7 +451,8 @@ int sslStart(fd, url, request, mime_hdr, size_ptr) strlen(buf), 30, sslErrorComplete, - (void *) sslState); + (void *) sslState, + xfree); return COMM_ERROR; } sslState = xcalloc(1, sizeof(SslStateData)); diff --git a/src/stat.cc b/src/stat.cc index 3f51d70f9d..92bdb5f5b7 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,5 +1,5 @@ /* - * $Id: stat.cc,v 1.42 1996/07/18 20:27:10 wessels Exp $ + * $Id: stat.cc,v 1.43 1996/07/20 03:16:55 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -882,7 +882,7 @@ void parameter_get(obj, sentry) } -void log_append(obj, url, id, size, action, method, http_code, msec, ident, hier) +void log_append(obj, url, id, size, action, method, http_code, msec, ident, hier, neighbor) cacheinfo *obj; char *url; char *id; @@ -893,10 +893,11 @@ void log_append(obj, url, id, size, action, method, http_code, msec, ident, hier int msec; char *ident; hier_code hier; + char *neighbor; { LOCAL_ARRAY(char, tmp, 6000); /* MAX_URL is 4096 */ - char *buf = NULL; int x; + static char *dash = "-"; getCurrentTime(); @@ -917,11 +918,13 @@ void log_append(obj, url, id, size, action, method, http_code, msec, ident, hier #endif if (!method) - method = "-"; + method = dash; if (!url) - url = "-"; + url = dash; if (!ident || ident[0] == '\0') - ident = "-"; + ident = dash; + if (!neighbor) + neighbor = dash; if (obj->logfile_status == LOG_ENABLE) { if (emulate_httpd_log) @@ -934,29 +937,28 @@ void log_append(obj, url, id, size, action, method, http_code, msec, ident, hier action, size); else - sprintf(tmp, "%9d.%03d %6d %s %s/%03d/%s %d %s %s %s\n", + sprintf(tmp, "%9d.%03d %6d %s %s/%03d %d %s %s %s %s/%s\n", (int) current_time.tv_sec, (int) current_time.tv_usec / 1000, msec, id, action, http_code, - hier_strings[hier], size, method, url, - ident); + ident, + hier_strings[hier], + neighbor); x = file_write(obj->logfile_fd, - buf = xstrdup(tmp), + xstrdup(tmp), strlen(tmp), obj->logfile_access, NULL, NULL, xfree); - if (x != DISK_OK) { + if (x != DISK_OK) debug(18, 1, "log_append: File write failed.\n"); - safe_free(buf); - } } } diff --git a/src/stmem.cc b/src/stmem.cc index bf7f9e09b6..c57a505b06 100644 --- a/src/stmem.cc +++ b/src/stmem.cc @@ -1,5 +1,5 @@ /* - * $Id: stmem.cc,v 1.13 1996/07/17 17:03:45 wessels Exp $ + * $Id: stmem.cc,v 1.14 1996/07/20 03:16:56 wessels Exp $ * * DEBUG: section 19 Memory Primitives * AUTHOR: Harvest Derived @@ -482,6 +482,13 @@ void stmemInit() mem_obj_pool.n_pages_in_use = 0; mem_obj_pool.max_pages = FD_SETSIZE >> 3; +#if PURIFY + sm_stats.max_pages = 0; + disk_stats.max_pages = 0; + request_pool.max_pages = 0; + mem_obj_pool.max_pages = 0; +#endif + init_stack(&sm_stats.free_page_stack, sm_stats.max_pages); init_stack(&disk_stats.free_page_stack, disk_stats.max_pages); init_stack(&request_pool.free_page_stack, request_pool.max_pages); diff --git a/src/store.cc b/src/store.cc index 919a408ee7..c64750130c 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,5 +1,5 @@ /* - * $Id: store.cc,v 1.72 1996/07/19 17:41:30 wessels Exp $ + * $Id: store.cc,v 1.73 1996/07/20 03:16:57 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -260,6 +260,7 @@ static void destroy_MemObject(mem) safe_free(mem->mime_hdr); safe_free(mem->reply); safe_free(mem->e_abort_msg); + safe_free(mem->hierarchy_host); requestUnlink(mem->request); mem->request = NULL; put_free_mem_obj(mem); @@ -1413,7 +1414,6 @@ static int storeDoRebuildFromDisk(data) &scan3, /* last modified */ &scan4, /* size */ url); /* url */ - debug(20, 9, "x = %d\n", x); if (x > 0) storeSwapFullPath(sfileno, swapfile); if (x != 6) { diff --git a/src/tunnel.cc b/src/tunnel.cc index f6d04bb0d8..03eab98d16 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -1,6 +1,6 @@ /* - * $Id: tunnel.cc,v 1.6 1996/07/18 20:27:09 wessels Exp $ + * $Id: tunnel.cc,v 1.7 1996/07/20 03:16:55 wessels Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -339,7 +339,8 @@ static void sslConnInProgress(fd, sslState) strlen(buf), 30, sslErrorComplete, - sslState); + sslState, + xfree); return; } } @@ -369,7 +370,8 @@ static int sslConnect(fd, hp, sslState) strlen(buf), 30, sslErrorComplete, - (void *) sslState); + (void *) sslState, + xfree); return COMM_ERROR; } debug(26, 5, "sslConnect: client=%d server=%d\n", @@ -402,7 +404,8 @@ static int sslConnect(fd, hp, sslState) strlen(buf), 30, sslErrorComplete, - (void *) sslState); + (void *) sslState, + xfree); return COMM_ERROR; } else { debug(26, 5, "sslConnect: conn %d EINPROGRESS\n", fd); @@ -448,7 +451,8 @@ int sslStart(fd, url, request, mime_hdr, size_ptr) strlen(buf), 30, sslErrorComplete, - (void *) sslState); + (void *) sslState, + xfree); return COMM_ERROR; } sslState = xcalloc(1, sizeof(SslStateData)); diff --git a/src/wais.cc b/src/wais.cc index 7bf85b4b83..a83e71b60d 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,5 +1,5 @@ /* - * $Id: wais.cc,v 1.33 1996/07/18 20:27:13 wessels Exp $ + * $Id: wais.cc,v 1.34 1996/07/20 03:16:58 wessels Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -297,7 +297,6 @@ static void waisSendComplete(fd, buf, size, errflag, data) (void *) waisState, getReadTimeout()); } - safe_free(buf); /* Allocated by waisSendRequest. */ } /* This will be called when connect completes. Write request. */ @@ -329,7 +328,8 @@ static void waisSendRequest(fd, waisState) len, 30, waisSendComplete, - (void *) waisState); + (void *) waisState, + xfree); if (BIT_TEST(waisState->entry->flag, CACHABLE)) storeSetPublicKey(waisState->entry); /* Make it public */ }