diff -urN squid-2.5.STABLE14/src/forward.c squid/src/forward.c --- squid-2.5.STABLE14/src/forward.c 2006-06-15 10:44:47.000000000 +0100 +++ squid/src/forward.c 2006-06-15 11:00:14.000000000 +0100 @@ -82,6 +82,9 @@ fwdStateFree(FwdState * fwdState) { StoreEntry *e = fwdState->entry; +#ifdef HS_FEAT_ICAP + StoreEntry *original_e = fwdState->original_entry; +#endif int sfd; peer *p; debug(17, 3) ("fwdStateFree: %p\n", fwdState); @@ -111,7 +114,49 @@ fwdState->request = NULL; if (fwdState->err) errorStateFree(fwdState->err); - storeUnregisterAbort(e); +#ifdef HS_FEAT_ICAP + if(original_e) { + storeUnregisterAbort(original_e); + + if(fwdState->icap_writer) { + if (EBIT_TEST(original_e->flags, ENTRY_ABORTED)) { + if(fwdState->icap_writer->icap_fd != -1) { + debug(17, 1) ("fwdStateFree: closing Icap FD %d\n", fwdState->icap_writer->icap_fd); + comm_close(fwdState->icap_writer->icap_fd); + } + else { + icapStateFree(-1, fwdState->icap_writer); + } + } + + cbdataUnlock(fwdState->icap_writer); + fwdState->icap_writer = 0; + } + + storeUnlockObject(original_e); + fwdState->original_entry = NULL; + } + else { +#endif + storeUnregisterAbort(e); +#ifdef HS_FEAT_ICAP + + if(fwdState->icap_writer) { + if (EBIT_TEST(e->flags, ENTRY_ABORTED)) { + if(fwdState->icap_writer->icap_fd != -1) { + debug(17, 1) ("fwdStateFree: closing Icap FD %d\n", fwdState->icap_writer->icap_fd); + comm_close(fwdState->icap_writer->icap_fd); + } + else { + icapStateFree(-1, fwdState->icap_writer); + } + } + cbdataUnlock(fwdState->icap_writer); + fwdState->icap_writer = 0; + } + } + +#endif storeUnlockObject(e); fwdState->entry = NULL; sfd = fwdState->server_fd; diff -urN squid-2.5.STABLE14/src/http.c squid/src/http.c --- squid-2.5.STABLE14/src/http.c 2006-06-15 10:44:47.000000000 +0100 +++ squid/src/http.c 2006-06-15 11:05:57.000000000 +0100 @@ -72,6 +72,16 @@ httpState->body_buf = NULL; } } + IcapStateData * icap = httpState->icap_writer; + if (icap != NULL) { + if (icap->respmod.entry != NULL) { + storeUnlockObject(icap->respmod.entry); + } + + if (!icap->flags.http_server_eof && -1 != icap->icap_fd) { + comm_close(icap->icap_fd); + } + } storeUnlockObject(httpState->entry); if (!memBufIsNull(&httpState->reply_hdr)) { memBufClean(&httpState->reply_hdr); @@ -963,8 +973,11 @@ * the icap server, rather than put it into * a StoreEntry */ - storeUnlockObject(httpState->entry); - storeUnregisterAbort(httpState->entry); + /* Even though we've passed our entry to the icap structure, we still need it + * for flow control when we've recieved a 204 so don't unlock just yet! We need + * to leave the abort call as well or we'll never unlock aborted StoreEntries! + * storeUnlockObject(httpState->entry); + * storeUnregisterAbort(httpState->entry); */ /* * create a bogus entry because the code assumes one is * always there. @@ -976,7 +989,10 @@ /* * pull a switcheroo on fwdState->entry. */ - storeUnlockObject(httpState->fwd->entry); + //storeUnlockObject(httpState->fwd->entry); + httpState->fwd->original_entry = httpState->fwd->entry; + httpState->fwd->icap_writer = httpState->icap_writer; + cbdataLock(httpState->fwd->icap_writer); httpState->fwd->entry = httpState->entry; storeLockObject(httpState->fwd->entry); /* diff -urN squid-2.5.STABLE14/src/icap_common.c squid/src/icap_common.c --- squid-2.5.STABLE14/src/icap_common.c 2006-06-15 10:44:47.000000000 +0100 +++ squid/src/icap_common.c 2006-06-15 11:07:16.000000000 +0100 @@ -282,7 +282,6 @@ if (icap->respmod.entry->store_status != STORE_OK) storeAbort(icap->respmod.entry); storeUnlockObject(icap->respmod.entry); - icap->respmod.entry = NULL; } requestUnlink(icap->request); icap->request = NULL; diff -urN squid-2.5.STABLE14/src/structs.h squid/src/structs.h --- squid-2.5.STABLE14/src/structs.h 2006-06-15 10:44:47.000000000 +0100 +++ squid/src/structs.h 2006-06-15 11:10:30.000000000 +0100 @@ -2165,6 +2165,10 @@ struct _FwdState { int client_fd; /* XXX unnecessary */ StoreEntry *entry; +#ifdef HS_FEAT_ICAP + StoreEntry *original_entry; + struct _IcapStateData *icap_writer; +#endif request_t *request; FwdServer *servers; int server_fd;