One side might delete the header before the other side was done with it.
This patch moves deletion of ->data->header to MsgPipeData class so that
it goes away only when the MsgPipe goes away.
virgin->source = this;
virgin->data = new MsgPipeData;
virgin->data->cause = NULL;
- virgin->data->header = requestLink(request);
+ virgin->data->setHeader(request);
virgin->data->body = new MemBuf;
virgin->data->body->init(ICAP::MsgPipeBufSizeMin, ICAP::MsgPipeBufSizeMax);
void ICAPClientReqmodPrecache::freeVirgin()
{
// virgin->data->cause should be NULL;
-
- if (virgin->data->header) {
- requestUnlink(dynamic_cast<HttpRequest*>(virgin->data->header));
- virgin->data->header = NULL;
- }
-
virgin = NULL; // refcounted
}
void ICAPClientReqmodPrecache::freeAdapted()
{
- if (adapted->data->header) {
- requestUnlink(dynamic_cast<HttpRequest*>(adapted->data->header));
- adapted->data->header = NULL;
- }
-
adapted = NULL; // refcounted
}
virgin = new MsgPipe("virgin"); // this is the place to create a refcount ptr
virgin->source = this;
virgin->data = new MsgPipeData;
- virgin->data->cause = requestLink(request);
- virgin->data->header = reply;
+ virgin->data->setCause(request);
+ virgin->data->setHeader(reply);
virgin->data->body = new MemBuf;
virgin->data->body->init(ICAP::MsgPipeBufSizeMin, ICAP::MsgPipeBufSizeMax);
#if ICAP_ANCHOR_LOOPBACK
adapted->data = new MsgPipeData;
- adapted->data->cause = request; // should not hurt
+ adapted->data->setCause(request); // should not hurt
#else
ICAPInitXaction(service, virgin, adapted);
#if ICAP_ANCHOR_LOOPBACK
/* simple assignments are not the right way to do this */
- adapted->data->header = virgin->data->header;
+ adapted->data->setHeader(virgin->data->header);
adapted->data->body = virgin->data->body;
noteSourceFinish(adapted);
return;
// ICAP client has received new HTTP headers (if any) at this point
void ICAPClientRespmodPrecache::noteSourceStart(MsgPipe *p)
{
- debug(93,5)("ICAPClientRespmodPrecache::noteSourceStart() called\n");
-
- /*
- * May want to assert that adapted != NULL here
- */
+ debugs(93,5, HERE << "ICAPClientRespmodPrecache::noteSourceStart() called");
HttpReply *reply = dynamic_cast<HttpReply*>(adapted->data->header);
/*
void ICAPClientRespmodPrecache::freeVirgin()
{
- requestUnlink(virgin->data->cause);
- virgin->data->cause = NULL;
- virgin->data->header = NULL;
virgin = NULL; // refcounted
}
void ICAPClientRespmodPrecache::freeAdapted()
{
- /*
- * Note on adapted->data->header. ICAPXaction-side created it
- * but gave control of it to us. Normally we give it to
- * HttpStateData::takeAdaptedHeader. If not, we have to
- * make sure it gets deleted;
- */
-
- if (adapted->data->header != NULL) {
- debug(93,3)("hey, adapted->data->header is still set!\n");
- delete adapted->data->header;
- adapted->data->header = NULL;
- }
-
adapted = NULL; // refcounted
}
state.sending = State::sendingDone;
- /*
- * adapted->data->header should be a link_count'ed HttpRequest
- */
-
- if (adapted->data->header) {
- requestUnlink(dynamic_cast<HttpRequest*>(adapted->data->header));
- adapted->data->header = NULL;
- }
-
adapted = NULL; // refcounted
}
return;
if (gotEncapsulated("res-hdr")) {
- adapted->data->header = new HttpReply;
+ adapted->data->setHeader(new HttpReply);
} else if (gotEncapsulated("req-hdr")) {
- adapted->data->header = requestLink(new HttpRequest);
+ adapted->data->setHeader(new HttpRequest);
} else
throw TexcHere("Neither res-hdr nor req-hdr in maybeAllocateHttpMsg()");
}
/*
- * $Id: MsgPipeData.h,v 1.3 2005/12/22 22:26:31 wessels Exp $
+ * $Id: MsgPipeData.h,v 1.4 2006/01/11 22:40:39 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
#define SQUID_MSGPIPEDATA_H
#include "HttpMsg.h"
+#include "HttpRequest.h"
+#include "HttpReply.h"
#include "MemBuf.h"
// MsgPipeData contains information about the HTTP message being sent
~MsgPipeData()
{
- assert(NULL == cause);
- assert(NULL == header);
+ clearCause();
+ clearHeader();
if (body) {
body->clean();
}
};
+ void setCause(HttpRequest *r)
+ {
+ cause = requestLink(r);
+ };
+
+ void setHeader(HttpMsg *msg)
+ {
+ clearHeader();
+
+ if (HttpRequest *req = dynamic_cast<HttpRequest*>(msg))
+ header = requestLink(req);
+ else if (HttpReply *rep = dynamic_cast<HttpReply*>(msg))
+ header = rep;
+ };
+
public:
typedef HttpMsg Header;
typedef MemBuf Body;
// HTTP request header for piped responses (the cause of the response)
HttpRequest *cause;
+
+private:
+
+ void clearCause()
+ {
+ requestUnlink(cause);
+ cause = NULL;
+ };
+
+ void clearHeader()
+ {
+ if (HttpRequest *req = dynamic_cast<HttpRequest*>(header))
+ requestUnlink(req);
+
+ header = NULL;
+ };
+
};
#endif /* SQUID_MSGPIPEDATA_H */