Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] [PATCH] Re: Freeing memory of se_alloc'ated object

From: Jeff Morriss <jeff.morriss.ws@xxxxxxxxx>
Date: Mon, 02 May 2011 15:38:32 -0400
Max wrote:
In this situation  it would
be perfect if se_alloc() engine could call a callback with a user
supplied argument before it starts to deallocate anything.
The init mechanism was created before the ephemeral memory stuff even existed, and has never been updated.

Some better mechanism, such as the one you suggest, would probably be a good idea.

I've developed a patch which implements such a mechanism and would
like it to be committed to the trunk.

Briefly: it costs one additional pointer per each memory chunk
allocated. Plus it costs thee additional pointers per allocation, if
allocation is made from pool in chunk mode when destructor is used,
otherwise it costs nothing. Callback is supplied as a parameter to
allocation function.

I would gladly read you comments, critics and suggestions regarding this patch.

Would it be simpler (and more generic) to have a "cleanup"/EOF routine similar to the init mechanism but called as soon as we reach (the final) EOF (before the se memory is freed)?

It could also be used to indicate to things like TCP desegmentation that we've reached EOF so TCP could attempt to desegment things marked DESEGMENT_UNTIL_FIN even though we haven't seen a FIN (see bug 3785). Any memory held hoping for more packets (e.g., the last fragments for reassembly) could be freed at the end of the capture instead of waiting for the file to be closed.