diff --git a/capinfos.c b/capinfos.c index 2bce743d26..c548f43f57 100644 --- a/capinfos.c +++ b/capinfos.c @@ -1710,6 +1710,10 @@ main(int argc, char *argv[]) exit: g_free(hash_buf); wtap_cleanup(); + free_progdirs(); +#ifdef HAVE_PLUGINS + plugins_cleanup(); +#endif return overall_error_status; } diff --git a/captype.c b/captype.c index 5858a392f8..8bff6f01b5 100644 --- a/captype.c +++ b/captype.c @@ -217,6 +217,10 @@ main(int argc, char *argv[]) } wtap_cleanup(); + free_progdirs(); +#ifdef HAVE_PLUGINS + plugins_cleanup(); +#endif return overall_error_status; } diff --git a/editcap.c b/editcap.c index b209e4fad7..ae691cf1b5 100644 --- a/editcap.c +++ b/editcap.c @@ -1898,6 +1898,10 @@ main(int argc, char *argv[]) wtap_close(wth); clean_exit: wtap_cleanup(); + free_progdirs(); +#ifdef HAVE_PLUGINS + plugins_cleanup(); +#endif return ret; error_on_exit: diff --git a/sharkd.c b/sharkd.c index 4ab49bf485..db797be5dd 100644 --- a/sharkd.c +++ b/sharkd.c @@ -300,6 +300,10 @@ clean_exit: col_cleanup(&cfile.cinfo); free_filter_lists(); wtap_cleanup(); + free_progdirs(); +#ifdef HAVE_PLUGINS + plugins_cleanup(); +#endif return ret; } diff --git a/tshark.c b/tshark.c index 470da75992..b244d78a6d 100644 --- a/tshark.c +++ b/tshark.c @@ -2203,6 +2203,10 @@ clean_exit: col_cleanup(&cfile.cinfo); free_filter_lists(); wtap_cleanup(); + free_progdirs(); +#ifdef HAVE_PLUGINS + plugins_cleanup(); +#endif cf_close(&cfile); return exit_status; } diff --git a/ui/gtk/main.c b/ui/gtk/main.c index bf3bc3b481..11c73fb835 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -2817,6 +2817,10 @@ clean_exit: col_cleanup(&cfile.cinfo); free_filter_lists(); wtap_cleanup(); + free_progdirs(); +#ifdef HAVE_PLUGINS + plugins_cleanup(); +#endif return ret; } diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index 4fcedd2d68..5ad28c59e9 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -948,6 +948,10 @@ clean_exit: #endif col_cleanup(&CaptureFile::globalCapFile()->cinfo); wtap_cleanup(); + free_progdirs(); +#ifdef HAVE_PLUGINS + plugins_cleanup(); +#endif return ret_val; } diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index 7ea4776a91..f820ef1df0 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -2191,6 +2191,16 @@ data_file_url(const gchar *filename) return uri; } +void +free_progdirs(void) +{ + g_free(progfile_dir); + g_free(plugin_dir); +#ifdef HAVE_EXTCAP + g_free(extcap_dir); +#endif +} + /* * Editor modelines * diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h index a45367a69b..ea467c49ee 100644 --- a/wsutil/filesystem.h +++ b/wsutil/filesystem.h @@ -304,6 +304,11 @@ WS_DLL_PUBLIC gboolean copy_file_binary_mode(const char *from_filename, */ WS_DLL_PUBLIC gchar* data_file_url(const gchar *filename); +/* + * Free the internal structtures + */ +WS_DLL_PUBLIC void free_progdirs(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/wsutil/plugins.c b/wsutil/plugins.c index 1f637c552b..2e8b7dcfe8 100644 --- a/wsutil/plugins.c +++ b/wsutil/plugins.c @@ -156,6 +156,10 @@ plugins_scan_dir(const char *dirname, plugin_load_failure_mode mode) gchar *dot; int cr; + if (!g_file_test(dirname, G_FILE_TEST_EXISTS) || !g_file_test(dirname, G_FILE_TEST_IS_DIR)) { + return; + } + if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL) { while ((file = ws_dir_read_name(dir)) != NULL) @@ -180,6 +184,7 @@ plugins_scan_dir(const char *dirname, plugin_load_failure_mode mode) #endif g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s", dirname, name); + if ((handle = g_module_open(filename, G_MODULE_BIND_LOCAL)) == NULL) { /* @@ -265,7 +270,6 @@ plugins_scan_dir(const char *dirname, plugin_load_failure_mode mode) g_free(new_plug); continue; } - } ws_dir_close(dir); } @@ -422,6 +426,29 @@ plugins_dump_all(void) plugins_get_descriptions(print_plugin_description, NULL); } +void +plugins_cleanup(void) +{ + plugin* prev; + plugin* cur; + + if (!plugin_list) + return; + + prev = plugin_list; + cur = plugin_list->next; + + do { + g_free(prev->name); + g_free(prev); + prev = cur; + cur = cur->next; + } while(cur); + + g_free(prev->name); + g_free(prev); +} + #endif /* HAVE_PLUGINS */ /* diff --git a/wsutil/plugins.h b/wsutil/plugins.h index 677c6d3f0b..89751ee2fb 100644 --- a/wsutil/plugins.h +++ b/wsutil/plugins.h @@ -45,6 +45,7 @@ typedef void (*plugin_description_callback)(const char *, const char *, void *); WS_DLL_PUBLIC void plugins_get_descriptions(plugin_description_callback callback, void *user_data); WS_DLL_PUBLIC void plugins_dump_all(void); +WS_DLL_PUBLIC void plugins_cleanup(void); #ifdef __cplusplus }