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

Wireshark-dev: [Wireshark-dev] Using global variables to store dissection information

From: Jakub Zawadzki <darkjames-ws@xxxxxxxxxxxx>
Date: Wed, 9 May 2012 00:26:56 +0200
Hi,

What's current policy of using global variables in dissectors?
Some time ago I've fixed some issues connected with storing ep_ memory in 
global variables: r42002, r42005, r42008 and prepared patch for bug #7060

And I'm *really* not happy when we add it, like recent commit to packet-dtn.c [1]
This commit seems safe, but I'd prefer to ban using global variables to store 
any information about current dissection.

AFAIK we also plan to have libwireshark thread-safe.
We can use TLS support in glib (GStaticPrivate[2]) or 
what compilers offers like __thread in GCC[3] or __declspec(thread) in MSVC[4]
or even mutex for whole protocol dissection 
but wouldn't be better to not use global variables?

There's already packet_info structure which is always private for current
dissection. The easiest fix would be to move all global variables 
to packet_info structure. Anyone against it?


[1] http://anonsvn.wireshark.org/viewvc/trunk/epan/dissectors/packet-dtn.c?r1=42507&r2=42506&pathrev=42507
[2] http://developer.gnome.org/glib/2.30/glib-Threads.html#GStaticPrivate
[3] http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-Local.html
[4] http://msdn.microsoft.com/en-us/library/6yh4a9k1.aspx