wsutil: remove leaks from filesystem and plugins code.

Change-Id: Iac2805c0130bd2ba6cdb3c9dd997050274d58d99
Reviewed-on: https://code.wireshark.org/review/20020
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Dario Lombardo 2017-02-08 14:25:57 +01:00 committed by Michael Mann
parent 19b97fbfb0
commit 6d79055ba6
11 changed files with 72 additions and 1 deletions

View File

@ -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;
}

View File

@ -217,6 +217,10 @@ main(int argc, char *argv[])
}
wtap_cleanup();
free_progdirs();
#ifdef HAVE_PLUGINS
plugins_cleanup();
#endif
return overall_error_status;
}

View File

@ -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:

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
*

View File

@ -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 */

View File

@ -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 */
/*

View File

@ -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
}