aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2017-09-10 23:38:36 +0100
committerJoão Valverde <j@v6e.pt>2017-09-11 16:48:49 +0000
commit69f0cb0cef3e8cc6b49073768f76ff1046ded8b5 (patch)
tree7a6314bf9e04fc5575a8c61df5f62c68be9e76c8 /wsutil
parente7aa63746ba630d88032394f4869fca2c87853a8 (diff)
wsutil: Initialize and store plugin personal dir
Obviate allocation on every call to get_plugins_pers_dir(). Change-Id: I089ae499f93739d490d4552f59b5db5996f7d26f Reviewed-on: https://code.wireshark.org/review/23495 Petri-Dish: João Valverde <j@v6e.pt> Reviewed-by: Michael Mann <mmann78@netscape.net> Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/filesystem.c26
-rw-r--r--wsutil/filesystem.h11
-rw-r--r--wsutil/plugins.c5
3 files changed, 24 insertions, 18 deletions
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index 939e4d3f05..2a2c4bab5f 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -959,6 +959,7 @@ get_datafile_dir(void)
* configure script.
*/
static char *plugin_dir = NULL;
+static char *plugin_pers_dir = NULL;
static void
init_plugin_dir(void)
@@ -1034,6 +1035,12 @@ init_plugin_dir(void)
}
#endif /* HAVE_PLUGINS || HAVE_LUA */
+static void
+init_plugin_pers_dir(void)
+{
+ plugin_pers_dir = get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
+}
+
/*
* Get the directory in which the plugins are stored.
*/
@@ -1048,6 +1055,15 @@ get_plugin_dir(void)
#endif
}
+/* Get the personal plugin dir */
+const char *
+get_plugins_pers_dir(void)
+{
+ if (!plugin_pers_dir)
+ init_plugin_pers_dir();
+ return plugin_pers_dir;
+}
+
#if defined(HAVE_EXTCAP)
/*
* Find the directory where the extcap hooks are stored.
@@ -1883,14 +1899,6 @@ get_datafile_path(const char *filename)
}
}
-/* Get the personal plugin dir */
-/* Return value is malloced so the caller should g_free() it. */
-char *
-get_plugins_pers_dir(void)
-{
- return get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
-}
-
/*
* Return an error message for UNIX-style errno indications on open or
* create operations.
@@ -2227,6 +2235,8 @@ free_progdirs(void)
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
g_free(plugin_dir);
plugin_dir = NULL;
+ g_free(plugin_pers_dir);
+ plugin_pers_dir = NULL;
#endif
#ifdef HAVE_EXTCAP
g_free(extcap_dir);
diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h
index f6c0e0899e..4ccc159ed7 100644
--- a/wsutil/filesystem.h
+++ b/wsutil/filesystem.h
@@ -56,6 +56,11 @@ WS_DLL_PUBLIC const char *get_progfile_dir(void);
WS_DLL_PUBLIC const char *get_plugin_dir(void);
/*
+ * Get the personal plugin dir.
+ */
+WS_DLL_PUBLIC const char *get_plugins_pers_dir(void);
+
+/*
* Get the directory in which extcap hooks are stored; this must not be called
* before init_progfile_dir() is called, as they might be stored in a
* subdirectory of the program file directory.
@@ -84,12 +89,6 @@ WS_DLL_PUBLIC const char *get_datafile_dir(void);
WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
/*
- * Get the personal plugin dir.
- * Return value is malloced so the caller should g_free() it.
- */
-WS_DLL_PUBLIC char *get_plugins_pers_dir(void);
-
-/*
* Get the directory in which files that, at least on UNIX, are
* system files (such as "/etc/ethers") are stored; on Windows,
* there's no "/etc" directory, so we get them from the Wireshark
diff --git a/wsutil/plugins.c b/wsutil/plugins.c
index 76bb59d770..047a6cb721 100644
--- a/wsutil/plugins.c
+++ b/wsutil/plugins.c
@@ -285,7 +285,6 @@ scan_plugins(plugin_load_failure_mode mode)
const char *plugin_dir;
const char *name;
char *plugin_dir_path;
- char *plugins_pers_dir;
WS_DIR *dir; /* scanned directory */
WS_DIRENT *file; /* current file */
@@ -353,9 +352,7 @@ scan_plugins(plugin_load_failure_mode mode)
*/
if (!started_with_special_privs())
{
- plugins_pers_dir = get_plugins_pers_dir();
- plugins_scan_dir(plugins_pers_dir, mode);
- g_free(plugins_pers_dir);
+ plugins_scan_dir(get_plugins_pers_dir(), mode);
}
}
}