diff --git a/dftest.c b/dftest.c index 1c7ba933b5..e9f1df6a23 100644 --- a/dftest.c +++ b/dftest.c @@ -31,8 +31,6 @@ #include #include -#include - #include "ui/util.h" #include "ui/cmdarg_err.h" #include "ui/failure_message.h" @@ -89,13 +87,6 @@ main(int argc, char **argv) timestamp_set_type(TS_RELATIVE); timestamp_set_seconds_type(TS_SECONDS_DEFAULT); - /* - * Libwiretap must be initialized before libwireshark is, so that - * dissection-time handlers for file-type-dependent blocks can - * register using the file type/subtype value for the file type. - */ - wtap_init(TRUE); - /* Register all dissectors; we must do this before checking for the "-g" flag, as the "-g" flag dumps a list of fields registered by the dissectors, and we must do it before we read the preferences, diff --git a/epan/epan.c b/epan/epan.c index 85a02ed4ac..9820a4327f 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -21,6 +21,7 @@ #include +#include #include #include "epan.h" @@ -246,6 +247,8 @@ epan_init(register_cb cb, gpointer client_data, gboolean load_plugins) wireshark_abort_on_too_many_items = FALSE; } + wtap_init(load_plugins); + /* * proto_init -> register_all_protocols -> g_async_queue_new which * requires threads to be initialized. This happens automatically with @@ -428,6 +431,8 @@ epan_cleanup(void) } wmem_cleanup_scopes(); + + wtap_cleanup(); } struct epan_session { diff --git a/wiretap/wtap.c b/wiretap/wtap.c index f1fdfc807b..5d40b9c1ce 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -25,6 +25,8 @@ #include #endif +static gboolean wiretap_initialized = FALSE; + #ifdef HAVE_PLUGINS static plugins_t *libwiretap_plugins = NULL; #endif @@ -1838,6 +1840,9 @@ wtap_full_file_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, void wtap_init(gboolean load_wiretap_plugins) { + if (wiretap_initialized) + return; + init_open_routines(); wtap_opttypes_initialize(); wtap_init_encap_types(); @@ -1848,6 +1853,7 @@ wtap_init(gboolean load_wiretap_plugins) #endif g_slist_foreach(wtap_plugins, call_plugin_register_wtap_module, NULL); } + wiretap_initialized = TRUE; } /* @@ -1856,6 +1862,9 @@ wtap_init(gboolean load_wiretap_plugins) void wtap_cleanup(void) { + if (!wiretap_initialized) + return; + wtap_cleanup_encap_types(); wtap_opttypes_cleanup(); ws_buffer_cleanup(); @@ -1866,6 +1875,7 @@ wtap_cleanup(void) plugins_cleanup(libwiretap_plugins); libwiretap_plugins = NULL; #endif + wiretap_initialized = FALSE; } /*