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] RFD: The Future of Memory Management in Wireshark

From: Jakub Zawadzki <darkjames-ws@xxxxxxxxxxxx>
Date: Mon, 29 Oct 2012 00:26:16 +0100
On Sun, Oct 28, 2012 at 10:12:41AM -0400, Evan Huus wrote:
> We might be able to fake the proper scoping using thread-local globals
> if we wrap everything in functions that assert the state of a
> dissection. Something like:
> 
> __thread wmem_allocator_t *packet_scope;
> __thread gboolean packet_in_scope = FALSE;

Just a note before commiting:

__thread is GCC extension, MVSC has got __declspec(thread) and
C11 has got _Thread_local.

So to be portable we must use glib GStaticPrivate.

> wmem_allocator_t *
> wmem_packet_scope(void)
> {
>   g_assert(packet_in_scope);
>   return packet_scope;
> }
> 
> void
> wmem_start_packet_scope(void)
> {
>   g_assert(!packet_in_scope);
>   packet_in_scope = TRUE;
> }
> 
> void
> wmem_stop_packet_scope(void)
> {
>   g_assert(packet_in_scope);
>   packet_in_scope = FALSE;
>   wmem_free_all(packet_scope);
> }
> 
> Invalid accesses would still compile, but at least they would throw an
> assertion as soon as the code path was hit. Thoughts on something like
> this?

I'm not sure if you want to replace all ep_ pool with packet_scope pool, 
but if yes what kind of memory you want to use in GUI, or for error messages 
in epan/dfilter/? glib allocator?

Cheers,
 Kuba.