Re: request_header_add adds a memory leak

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Fri, 20 Jul 2012 09:52:04 -0600

On 07/19/2012 08:40 PM, Amos Jeffries wrote:
> On 20/07/2012 12:34 p.m., Alex Rousskov wrote:
>> Hello,
>>
>> I believe the current trunk is profusely leaking memory. There may
>> be several reasons, but my current suspect is a circular RefCounted
>> reference that allows neither HttpRequest nor AccessLogEntry to be freed:
>>
>> HttpRequest -> AccessLogEntry -> HttpRequest
>>
>> The circle was created by the request_header_add feature during the
>> review process, when it was decided that we should reuse the Format API
>> to expand macros in the added header values. That API needs
>> AccessLogEntry. This is good news -- there is not much code relying on
>> the circle existence!
>>
>> The bad news is that breaking the circle is not trivial. Copying
>> AccessLogEntry to HttpRequest (instead of linking the two) is not a good
>> option because the AccessLogEntry object needs to be populated with
>> values collected throughout the master transaction lifetime -- up until
>> httpHdrAdd() is called on the server side (and much later when we start
>> supporting macros in mangled responses).

> However, when the transaction reaches termination and logging is
> completed it becomes no longer useful (next transaction must re-fill
> with new details specific to that transaction).
>
> A clear() method on the entry would be good for resetting all its
> pointers after logging completion.

When the master transaction is completed, the master transaction object
(currently AccessLogEntry) should no longer be used, and when it is no
longer used, it must be destroyed. That clear() method is the existing
AccessLogEntry destructor (triggered by refcounting). If we break the
refcounting loop, this destruction will happen.

>> The mess stems from the fact that AccessLogEntry is not generally
>> available on the server side. HttpRequest is available there but it
>> cannot be used for AccessLogEntry smuggling (due to the above loop).
>>
>> Unless I hear better ideas, I will extend the FwdState::fwdStart() API
>> to supply an AccessLogEntry (and store it in Server/etc). This may even
>> help with future plans of converting ALE into some kind of MasterXaction
>> class.
>
> Both would be good loong-term, but up to you which gets chosen. I'm
> inclined to leave the API changes until xaction project can be started
> properly.

Both? I have only outlined one solution (FwdState::fwdStart() API and
related changes). Which one is the second one?

Thank you,

Alex.
Received on Fri Jul 20 2012 - 15:52:24 MDT

This archive was generated by hypermail 2.2.0 : Fri Jul 20 2012 - 12:00:02 MDT