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] Wireshark Final Cleanup Function/Hook?

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Tue, 28 Aug 2012 16:07:13 -0700
On Aug 27, 2012, at 5:58 PM, Dirk Jagdmann wrote:

> is there a way to register a cleanup function in a dissector to be called when a file closed? I have a couple of hash tables allocated using g_hash_table_new() that I want to free when the user closes the file.

Literally speaking, not at present.  However, you can register a routine to be called when a file is *opened*, and have that routine free up any old stuff, if any, remaining from a previous capture.  See register_init_routine().

Arguably, there should be separate "initialize" and "finish" routines.

In addition, as Joerg noted, for some purposes you might want to use Wireshark's memory-chunk allocators and allocate "seasonal" memory ("seasons" begin when a capture is opened and end when a capture is closed).