From 9d9f2bc06e1fb2452b2d77c0ca8c0d3ab07b2b42 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Tue, 10 Jan 2006 03:17:45 +0000 Subject: [PATCH] using requestLink on adapted->data->header fixes an HttpRequest memory leak with malformed ICAP/HTTP responses. --- src/ICAP/ICAPClientReqmodPrecache.cc | 14 +++++++++++--- src/ICAP/ICAPModXact.cc | 14 +++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ICAP/ICAPClientReqmodPrecache.cc b/src/ICAP/ICAPClientReqmodPrecache.cc index 00ffcb7ac3..ae91578eca 100644 --- a/src/ICAP/ICAPClientReqmodPrecache.cc +++ b/src/ICAP/ICAPClientReqmodPrecache.cc @@ -182,13 +182,21 @@ void ICAPClientReqmodPrecache::stop(Notify notify) void ICAPClientReqmodPrecache::freeVirgin() { // virgin->data->cause should be NULL; - requestUnlink(dynamic_cast(virgin->data->header)); - virgin->data->header = NULL; + + if (virgin->data->header) { + requestUnlink(dynamic_cast(virgin->data->header)); + virgin->data->header = NULL; + } + virgin = NULL; // refcounted } void ICAPClientReqmodPrecache::freeAdapted() { - adapted->data->header = NULL; // we don't own it + if (adapted->data->header) { + requestUnlink(dynamic_cast(adapted->data->header)); + adapted->data->header = NULL; + } + adapted = NULL; // refcounted } diff --git a/src/ICAP/ICAPModXact.cc b/src/ICAP/ICAPModXact.cc index b6055b3c80..51189b7b34 100644 --- a/src/ICAP/ICAPModXact.cc +++ b/src/ICAP/ICAPModXact.cc @@ -495,10 +495,14 @@ void ICAPModXact::stopSending(bool nicely) state.sending = State::sendingDone; /* - * Note on adapted->data->header: we created the header, but allow the - * other side (ICAPClientRespmodPrecache) to take control of it. We won't touch it here - * and instead rely on the Anchor-side to make sure it is properly freed. - */ + * adapted->data->header should be a link_count'ed HttpRequest + */ + + if (adapted->data->header) { + requestUnlink(dynamic_cast(adapted->data->header)); + adapted->data->header = NULL; + } + adapted = NULL; // refcounted } @@ -542,7 +546,7 @@ void ICAPModXact::maybeAllocateHttpMsg() if (gotEncapsulated("res-hdr")) { adapted->data->header = new HttpReply; } else if (gotEncapsulated("req-hdr")) { - adapted->data->header = new HttpRequest; + adapted->data->header = requestLink(new HttpRequest); } else throw TexcHere("Neither res-hdr nor req-hdr in maybeAllocateHttpMsg()"); } -- 2.47.2