capture_opts: free memory on exit to avoid leak.

This required a restyle of the way the different apps exit.

Change-Id: Iedf728488954cc415b620ff0284d2e60f38f87d2
Reviewed-on: https://code.wireshark.org/review/19780
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
This commit is contained in:
Dario Lombardo 2017-01-25 10:16:35 +01:00
parent 844cf1ac90
commit 93a5c83f0a
7 changed files with 221 additions and 102 deletions

View File

@ -121,6 +121,12 @@ capture_opts_init(capture_options *capture_opts)
capture_opts->capture_child = FALSE;
}
void
capture_opts_cleanup(capture_options *capture_opts)
{
g_array_free(capture_opts->ifaces, TRUE);
g_array_free(capture_opts->all_ifaces, TRUE);
}
/* log content of capture_opts */
void

View File

@ -326,6 +326,10 @@ typedef struct capture_options_tag {
extern void
capture_opts_init(capture_options *capture_opts);
/* clean internal structures */
extern void
capture_opts_cleanup(capture_options *capture_opts);
/* set a command line option value */
extern int
capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);

View File

@ -1132,6 +1132,7 @@ exit_main(int status)
#endif /* _WIN32 */
capture_opts_cleanup(&global_capture_opts);
exit(status);
}

View File

@ -1057,7 +1057,10 @@ void echld_dispatcher_start(int* in_pipe_fds, int* out_pipe_fds, char* argv0, in
preinit_epan(argv0,main);
DISP_WRITE(dispatcher->parent_out, NULL, 0, ECHLD_HELLO, 0);
exit(dispatcher_loop());
ret = dispatcher_loop();
capture_opts_cleanup(dispatcher->capture_opts);
exit(ret);
}
/*

246
tshark.c
View File

@ -134,6 +134,17 @@
#include <wsutil/plugins.h>
#endif
/* Exit codes */
#define INVALID_OPTION 1
#define INVALID_INTERFACE 2
#define INVALID_FILE 2
#define INVALID_FILTER 2
#define INVALID_EXPORT 2
#define INVALID_CAPABILITY 2
#define INVALID_TAP 2
#define INVALID_DATA_LINK 2
#define INVALID_CAPTURE 2
#define INIT_FAILED 2
#if 0
#define tshark_debug(...) g_warning(__VA_ARGS__)
@ -655,11 +666,10 @@ main(int argc, char *argv[])
int dp_open_errno, dp_read_errno;
int cf_open_errno;
int err;
volatile int exit_status = 0;
volatile int exit_status = EXIT_SUCCESS;
#ifdef HAVE_LIBPCAP
gboolean list_link_layer_types = FALSE;
gboolean start_capture = FALSE;
int status;
GList *if_list;
gchar *err_str;
#else
@ -804,7 +814,8 @@ main(int argc, char *argv[])
set_profile_name (optarg);
} else {
cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
break;
case 'P': /* Print packet summary info even when writing to a file */
@ -900,8 +911,10 @@ main(int argc, char *argv[])
dissectors, and we must do it before we read the preferences, in
case any dissectors register preferences. */
if (!epan_init(register_all_protocols, register_all_protocol_handoffs, NULL,
NULL))
return 2;
NULL)) {
exit_status = INIT_FAILED;
goto clean_exit;
}
/* Register all tap listeners; we do this before we parse the arguments,
as the "-z" argument can specify a registered tap. */
@ -951,7 +964,8 @@ main(int argc, char *argv[])
dissector_dump_dissector_tables();
else if (strcmp(argv[2], "fieldcount") == 0) {
/* return value for the test suite */
return proto_registrar_dump_fieldcount();
exit_status = proto_registrar_dump_fieldcount();
goto clean_exit;
} else if (strcmp(argv[2], "fields") == 0)
proto_registrar_dump_fields();
else if (strcmp(argv[2], "folders") == 0)
@ -978,10 +992,12 @@ main(int argc, char *argv[])
glossary_option_help();
else {
cmdarg_err("Invalid \"%s\" option for -G flag, enter -G ? for more help.", argv[2]);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
return 0;
exit_status = EXIT_SUCCESS;
goto clean_exit;
}
/* load the decode as entries of this profile */
@ -1109,9 +1125,9 @@ main(int argc, char *argv[])
case 'B': /* Buffer size */
#endif
#ifdef HAVE_LIBPCAP
status = capture_opts_add_opt(&global_capture_opts, opt, optarg, &start_capture);
if (status != 0) {
return status;
exit_status = capture_opts_add_opt(&global_capture_opts, opt, optarg, &start_capture);
if (exit_status != 0) {
goto clean_exit;
}
#else
if (opt == 'w') {
@ -1139,11 +1155,13 @@ main(int argc, char *argv[])
cmdarg_err("%s", err_str);
g_free(err_str);
}
return 2;
exit_status = INVALID_INTERFACE;
goto clean_exit;
}
capture_opts_print_interfaces(if_list);
free_interface_list(if_list);
return 0;
exit_status = EXIT_SUCCESS;
goto clean_exit;
#else
capture_option_specified = TRUE;
arg_error = TRUE;
@ -1158,7 +1176,8 @@ main(int argc, char *argv[])
if (!output_fields_set_option(output_fields, optarg)) {
cmdarg_err("\"%s\" is not a valid field output option=value pair.", optarg);
output_fields_list_options(stderr);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
break;
case 'F':
@ -1166,7 +1185,8 @@ main(int argc, char *argv[])
if (out_file_type < 0) {
cmdarg_err("\"%s\" isn't a valid capture file type", optarg);
list_capture_types();
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
break;
case 'j':
@ -1179,14 +1199,16 @@ main(int argc, char *argv[])
} else {
cmdarg_err("Invalid -W argument \"%s\"; it must be one of:", optarg);
cmdarg_err_cont("\t'n' write network address resolution information (pcapng only)");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
break;
case 'H': /* Read address to name mappings from a hosts file */
if (! add_hosts_file(optarg))
{
cmdarg_err("Can't read host entries from \"%s\"", optarg);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
out_file_name_res = TRUE;
break;
@ -1197,7 +1219,8 @@ main(int argc, char *argv[])
"See https://www.wireshark.org for more information.\n",
get_ws_vcs_version_info());
print_usage(stdout);
return 0;
exit_status = EXIT_SUCCESS;
goto clean_exit;
break;
case 'l': /* "Line-buffer" standard output */
/* This isn't line-buffering, strictly speaking, it's just
@ -1230,13 +1253,15 @@ main(int argc, char *argv[])
case PREFS_SET_SYNTAX_ERR:
cmdarg_err("Invalid -o flag \"%s\"", optarg);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
break;
case PREFS_SET_NO_SUCH_PREF:
case PREFS_SET_OBSOLETE:
cmdarg_err("-o flag \"%s\" specifies unknown preference", optarg);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
break;
}
break;
@ -1312,7 +1337,8 @@ main(int argc, char *argv[])
"\t packets, or a multi-line view of the details of each of the\n"
"\t packets, depending on whether the -V flag was specified.\n"
"\t This is the default.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
break;
case 'U': /* Export PDUs to file */
@ -1324,7 +1350,8 @@ main(int argc, char *argv[])
for (export_pdu_tap_name_list = get_export_pdu_tap_list(); export_pdu_tap_name_list; export_pdu_tap_name_list = g_slist_next(export_pdu_tap_name_list)) {
cmdarg_err("%s\n", (const char*)(export_pdu_tap_name_list->data));
}
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
pdu_export_arg = g_strdup(optarg);
break;
@ -1345,7 +1372,8 @@ main(int argc, char *argv[])
#ifdef HAVE_EXTCAP
extcap_cleanup();
#endif
return 0;
exit_status = EXIT_SUCCESS;
goto clean_exit;
case 'O': /* Only output these protocols */
/* already processed; just ignore it now */
break;
@ -1370,12 +1398,14 @@ main(int argc, char *argv[])
if (strcmp("help", optarg) == 0) {
fprintf(stderr, "tshark: The available statistics for the \"-z\" option are:\n");
list_stat_cmd_args();
return 0;
exit_status = EXIT_SUCCESS;
goto clean_exit;
}
if (!process_stat_cmd_arg(optarg)) {
cmdarg_err("Invalid -z argument \"%s\"; it must be one of:", optarg);
list_stat_cmd_args();
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
break;
case 'd': /* Decode as rule */
@ -1388,17 +1418,22 @@ main(int argc, char *argv[])
case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */
case LONGOPT_ENABLE_PROTOCOL: /* enable dissection of protocol (that is disabled by default) */
if (!dissect_opts_handle_opt(opt, optarg))
return 1;
if (!dissect_opts_handle_opt(opt, optarg)) {
exit_status = INVALID_OPTION;
goto clean_exit;
}
break;
case LONGOPT_EXPORT_OBJECTS: /* --export-objects */
if (strcmp("help", optarg) == 0) {
fprintf(stderr, "tshark: The available export object types for the \"--export-objects\" option are:\n");
eo_list_object_types();
return 0;
exit_status = EXIT_SUCCESS;
goto clean_exit;
}
if (!eo_tap_opt_add(optarg)) {
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (!eo_tap_opt_add(optarg))
return 1;
break;
default:
case '?': /* Bad flag - print usage message */
@ -1409,7 +1444,8 @@ main(int argc, char *argv[])
default:
print_usage(stderr);
}
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
break;
}
}
@ -1418,12 +1454,14 @@ main(int argc, char *argv[])
if ((WRITE_FIELDS != output_action && WRITE_XML != output_action && WRITE_JSON != output_action && WRITE_EK != output_action) && 0 != output_fields_num_fields(output_fields)) {
cmdarg_err("Output fields were specified with \"-e\", "
"but \"-Tek, -Tfields, -Tjson or -Tpdml\" was not specified.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
} else if (WRITE_FIELDS == output_action && 0 == output_fields_num_fields(output_fields)) {
cmdarg_err("\"-Tfields\" was specified, but no fields were "
"specified with \"-e\".");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
/* If no capture filter or display filter has been specified, and there are
@ -1435,7 +1473,8 @@ main(int argc, char *argv[])
if (dfilter != NULL) {
cmdarg_err("Display filters were specified both with \"-d\" "
"and with additional command-line arguments.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
dfilter = get_args_as_string(argc, argv, optind);
} else {
@ -1445,7 +1484,8 @@ main(int argc, char *argv[])
if (global_capture_opts.default_options.cfilter) {
cmdarg_err("A default capture filter was specified both with \"-f\""
" and with additional command-line arguments.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
interface_options interface_opts;
@ -1457,7 +1497,8 @@ main(int argc, char *argv[])
} else {
cmdarg_err("A capture filter was specified both with \"-f\""
" and with additional command-line arguments.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
global_capture_opts.default_options.cfilter = get_args_as_string(argc, argv, optind);
@ -1482,7 +1523,8 @@ main(int argc, char *argv[])
if (strcmp(global_capture_opts.save_file, "-") == 0 && print_packet_info) {
cmdarg_err("You can't write both raw packet data and dissected packets"
" to the standard output.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
#else
@ -1498,13 +1540,15 @@ main(int argc, char *argv[])
#endif
if (arg_error) {
print_usage(stderr);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (print_hex) {
if (output_action != WRITE_TEXT && output_action != WRITE_JSON && output_action != WRITE_EK) {
cmdarg_err("Raw packet hex data can only be printed as text, PostScript, JSON or EK JSON");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
@ -1513,7 +1557,8 @@ main(int argc, char *argv[])
if (!print_details) {
cmdarg_err("-O requires -V");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
output_only_tables = g_hash_table_new (g_str_hash, g_str_equal);
@ -1524,7 +1569,8 @@ main(int argc, char *argv[])
if (rfilter != NULL && !perform_two_pass_analysis) {
cmdarg_err("-R without -2 is deprecated. For single-pass filtering use -Y.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
#ifdef HAVE_LIBPCAP
@ -1534,12 +1580,14 @@ main(int argc, char *argv[])
if (cf_name) {
/* Yes - that's bogus. */
cmdarg_err("You can't specify -L and a capture file to be read.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
/* No - did they specify a ring buffer option? */
if (global_capture_opts.multi_files_on) {
cmdarg_err("Ring buffer requested, but a capture isn't being done.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
} else {
if (cf_name) {
@ -1554,33 +1602,39 @@ main(int argc, char *argv[])
if (global_capture_opts.default_options.cfilter) {
cmdarg_err("Only read filters, not capture filters, "
"can be specified when reading a capture file.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.multi_files_on) {
cmdarg_err("Multiple capture files requested, but "
"a capture isn't being done.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.has_file_duration) {
cmdarg_err("Switching capture files after a time interval was specified, but "
"a capture isn't being done.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.has_ring_num_files) {
cmdarg_err("A ring buffer of capture files was specified, but "
"a capture isn't being done.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.has_autostop_files) {
cmdarg_err("A maximum number of capture files was specified, but "
"a capture isn't being done.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.capture_comment) {
cmdarg_err("A capture comment was specified, but "
"a capture isn't being done.\nThere's no support for adding "
"a capture comment to an existing capture file.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
/* Note: TShark now allows the restriction of a _read_ file by packet count
@ -1590,7 +1644,8 @@ main(int argc, char *argv[])
if (global_capture_opts.has_autostop_duration) {
cmdarg_err("A maximum capture time was specified, but "
"a capture isn't being done.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
} else {
/*
@ -1601,7 +1656,8 @@ main(int argc, char *argv[])
* to buffer packets until we've read all of them, but a live capture
* has no useful/meaningful definition of "all" */
cmdarg_err("Live captures do not support two-pass analysis.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.saving_to_file) {
@ -1611,12 +1667,14 @@ main(int argc, char *argv[])
if (out_file_type != WTAP_FILE_TYPE_SUBTYPE_PCAP &&
out_file_type != WTAP_FILE_TYPE_SUBTYPE_PCAPNG) {
cmdarg_err("Live captures can only be saved in pcap or pcapng format.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.capture_comment &&
out_file_type != WTAP_FILE_TYPE_SUBTYPE_PCAPNG) {
cmdarg_err("A capture comment can only be written to a pcapng file.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.multi_files_on) {
/* Multiple-file mode doesn't work under certain conditions:
@ -1626,29 +1684,34 @@ main(int argc, char *argv[])
if (strcmp(global_capture_opts.save_file, "-") == 0) {
cmdarg_err("Multiple capture files requested, but "
"the capture is being written to the standard output.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.output_to_pipe) {
cmdarg_err("Multiple capture files requested, but "
"the capture file is a pipe.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (!global_capture_opts.has_autostop_filesize &&
!global_capture_opts.has_file_duration) {
cmdarg_err("Multiple capture files requested, but "
"no maximum capture file size or duration was specified.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
/* Currently, we don't support read or display filters when capturing
and saving the packets. */
if (rfilter != NULL) {
cmdarg_err("Read filters aren't supported when capturing and saving the captured packets.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (dfilter != NULL) {
cmdarg_err("Display filters aren't supported when capturing and saving the captured packets.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
global_capture_opts.use_pcapng = (out_file_type == WTAP_FILE_TYPE_SUBTYPE_PCAPNG) ? TRUE : FALSE;
} else {
@ -1658,17 +1721,20 @@ main(int argc, char *argv[])
if (global_capture_opts.has_autostop_filesize) {
cmdarg_err("Maximum capture file size specified, but "
"capture isn't being saved to a file.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.multi_files_on) {
cmdarg_err("Multiple capture files requested, but "
"the capture isn't being saved to a file.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (global_capture_opts.capture_comment) {
cmdarg_err("A capture comment was specified, but "
"the capture isn't being saved to a file.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
}
@ -1706,7 +1772,8 @@ main(int argc, char *argv[])
cmdarg_err_cont("\t%s", (gchar *)it->data);
}
g_slist_free(invalid_fields);
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
#ifdef HAVE_LIBPCAP
@ -1716,11 +1783,13 @@ main(int argc, char *argv[])
global_capture_opts.output_to_pipe) {
if (tap_listeners_require_dissection()) {
cmdarg_err("Taps aren't supported when saving to a pipe.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
if (print_packet_info) {
cmdarg_err("Printing dissected packets isn't supported when saving to a pipe.");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
#endif
@ -1731,7 +1800,8 @@ main(int argc, char *argv[])
if (in_file_type == WTAP_TYPE_AUTO) {
cmdarg_err("\"%s\" isn't a valid read file format type", name? name : "");
list_read_capture_types();
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
}
@ -1808,7 +1878,8 @@ main(int argc, char *argv[])
}
}
#endif
return 2;
exit_status = INVALID_INTERFACE;
goto clean_exit;
}
}
cfile.rfcode = rfcode;
@ -1837,7 +1908,8 @@ main(int argc, char *argv[])
}
}
#endif
return 2;
exit_status = INVALID_FILTER;
goto clean_exit;
}
}
cfile.dfcode = dfcode;
@ -1873,7 +1945,8 @@ main(int argc, char *argv[])
if (!cf_name) {
cmdarg_err("PDUs export requires a capture file (specify with -r).");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
/* Take ownership of the '-w' output file. */
#ifdef HAVE_LIBPCAP
@ -1885,7 +1958,8 @@ main(int argc, char *argv[])
#endif
if (exp_pdu_filename == NULL) {
cmdarg_err("PDUs export requires an output file (-w).");
return 1;
exit_status = INVALID_OPTION;
goto clean_exit;
}
exp_pdu_error = exp_pdu_pre_open(exp_pdu_tap_name, exp_pdu_filter,
@ -1893,13 +1967,15 @@ main(int argc, char *argv[])
if (exp_pdu_error) {
cmdarg_err("Cannot register tap: %s", exp_pdu_error);
g_free(exp_pdu_error);
return 2;
exit_status = INVALID_TAP;
goto clean_exit;
}
exp_fd = ws_open(exp_pdu_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (exp_fd == -1) {
cmdarg_err("%s: %s", exp_pdu_filename, file_open_error_message(errno, TRUE));
return 2;
exit_status = INVALID_FILE;
goto clean_exit;
}
/* Activate the export PDU tap */
@ -1907,7 +1983,8 @@ main(int argc, char *argv[])
g_strdup_printf("Dump of PDUs from %s", cf_name));
if (err != 0) {
cmdarg_err("Failed to start the PDU export: %s", g_strerror(err));
return 2;
exit_status = INVALID_EXPORT;
goto clean_exit;
}
}
@ -1936,7 +2013,8 @@ main(int argc, char *argv[])
#ifdef HAVE_EXTCAP
extcap_cleanup();
#endif
return 2;
exit_status = INVALID_FILE;
goto clean_exit;
}
/* Process the packets in the file */
@ -1984,8 +2062,9 @@ main(int argc, char *argv[])
/* if no interface was specified, pick a default */
exit_status = capture_opts_default_iface_if_necessary(&global_capture_opts,
((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL);
if (exit_status != 0)
return exit_status;
if (exit_status != 0) {
goto clean_exit;
}
/* if requested, list the link layer types and exit */
if (list_link_layer_types) {
@ -2008,16 +2087,19 @@ main(int argc, char *argv[])
if (caps == NULL) {
cmdarg_err("%s", err_str);
g_free(err_str);
return 2;
exit_status = INVALID_CAPABILITY;
goto clean_exit;
}
if (caps->data_link_types == NULL) {
cmdarg_err("The capture device \"%s\" has no data link types.", interface_opts.name);
return 2;
exit_status = INVALID_DATA_LINK;
goto clean_exit;
}
capture_opts_print_if_capabilities(caps, interface_opts.name, interface_opts.monitor_mode);
free_if_capabilities(caps);
}
return 0;
exit_status = EXIT_SUCCESS;
goto clean_exit;
}
/*
@ -2055,7 +2137,8 @@ main(int argc, char *argv[])
if (print_packet_info) {
if (!write_preamble(&cfile)) {
show_print_file_io_error(errno);
return 2;
exit_status = INVALID_FILE;
goto clean_exit;
}
}
@ -2082,7 +2165,8 @@ main(int argc, char *argv[])
#else
/* No - complain. */
cmdarg_err("This version of TShark was not built with support for capturing packets.");
return 2;
exit_status = INVALID_CAPTURE;
goto clean_exit;
#endif
}
@ -2104,6 +2188,8 @@ main(int argc, char *argv[])
output_fields_free(output_fields);
output_fields = NULL;
clean_exit:
capture_opts_cleanup(&global_capture_opts);
return exit_status;
}

View File

@ -208,6 +208,10 @@
#include <gtkmacintegration/gtkosxapplication.h>
#endif
#define INIT_FAILED 2
#define INVALID_CAPABILITY 2
#define INVALID_LINK_TYPE 2
/*
* Files under personal and global preferences directories in which
* GTK settings for Wireshark are stored.
@ -2056,7 +2060,7 @@ main(int argc, char *argv[])
{
char *init_progfile_dir_error;
char *s;
int ret = EXIT_SUCCESS;
extern int info_update_freq; /* Found in about_dlg.c. */
const gchar *filter;
@ -2070,7 +2074,6 @@ main(int argc, char *argv[])
int err;
#ifdef HAVE_LIBPCAP
gchar *err_str;
int status;
#else
#ifdef _WIN32
#ifdef HAVE_AIRPCAP
@ -2315,8 +2318,10 @@ main(int argc, char *argv[])
dissectors, and we must do it before we read the preferences, in
case any dissectors register preferences. */
if (!epan_init(register_all_protocols,register_all_protocol_handoffs,
splash_update, (gpointer) splash_win))
return 2;
splash_update, (gpointer) splash_win)) {
ret = INIT_FAILED;
goto clean_exit;
}
splash_update(RA_LISTENERS, NULL, (gpointer)splash_win);
@ -2371,10 +2376,10 @@ main(int argc, char *argv[])
/* We're supposed to do a live capture or get a list of link-layer
types for a live capture device; if the user didn't specify an
interface to use, pick a default. */
status = capture_opts_default_iface_if_necessary(&global_capture_opts,
ret = capture_opts_default_iface_if_necessary(&global_capture_opts,
((global_commandline_info.prefs_p->capture_device) && (*global_commandline_info.prefs_p->capture_device != '\0')) ? get_if_name(global_commandline_info.prefs_p->capture_device) : NULL);
if (status != 0) {
exit(status);
if (ret != 0) {
goto clean_exit;
}
}
@ -2403,11 +2408,13 @@ main(int argc, char *argv[])
if (caps == NULL) {
cmdarg_err("%s", err_str);
g_free(err_str);
exit(2);
ret = INVALID_CAPABILITY;
goto clean_exit;
}
if (caps->data_link_types == NULL) {
cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
exit(2);
ret = INVALID_LINK_TYPE;
goto clean_exit;
}
#ifdef _WIN32
create_console();
@ -2423,7 +2430,8 @@ main(int argc, char *argv[])
free_if_capabilities(caps);
}
}
exit(0);
ret = EXIT_SUCCESS;
goto clean_exit;
}
capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
capture_opts_trim_ring_num_files(&global_capture_opts);
@ -2802,7 +2810,9 @@ main(int argc, char *argv[])
main_unregister_resource();
#endif
exit(0);
clean_exit:
capture_opts_cleanup(&global_capture_opts);
return ret;
}
#ifdef _WIN32

View File

@ -124,6 +124,10 @@
#include <QTextCodec>
#endif
#define INIT_FAILED 2
#define INVALID_CAPABILITY 2
#define INVALID_LINK_TYPE 2
//#define DEBUG_STARTUP_TIME 1
/*
# Log level
@ -331,7 +335,7 @@ int main(int argc, char *qt_argv[])
#ifdef _WIN32
int opt;
#endif
int ret_val;
int ret_val = EXIT_SUCCESS;
char **argv = qt_argv;
#ifdef _WIN32
@ -343,7 +347,6 @@ int main(int argc, char *qt_argv[])
char *gdp_path, *dp_path;
#ifdef HAVE_LIBPCAP
gchar *err_str;
int status;
#else
#ifdef _WIN32
#ifdef HAVE_AIRPCAP
@ -351,6 +354,7 @@ int main(int argc, char *qt_argv[])
#endif
#endif
#endif
gchar *err_msg = NULL;
GString *comp_info_str = NULL;
GString *runtime_info_str = NULL;
@ -593,7 +597,8 @@ int main(int argc, char *qt_argv[])
if (!epan_init(register_all_protocols,register_all_protocol_handoffs,
splash_update, NULL)) {
SimpleDialog::displayQueuedMessages(main_w);
return 2;
ret_val = INIT_FAILED;
goto clean_exit;
}
#ifdef DEBUG_STARTUP_TIME
/* epan_init resets the preferences */
@ -680,10 +685,10 @@ int main(int argc, char *qt_argv[])
/* We're supposed to do a live capture or get a list of link-layer
types for a live capture device; if the user didn't specify an
interface to use, pick a default. */
status = capture_opts_default_iface_if_necessary(&global_capture_opts,
ret_val = capture_opts_default_iface_if_necessary(&global_capture_opts,
((global_commandline_info.prefs_p->capture_device) && (*global_commandline_info.prefs_p->capture_device != '\0')) ? get_if_name(global_commandline_info.prefs_p->capture_device) : NULL);
if (status != 0) {
exit(status);
if (ret_val != 0) {
goto clean_exit;
}
}
@ -704,11 +709,13 @@ int main(int argc, char *qt_argv[])
if (caps == NULL) {
cmdarg_err("%s", err_str);
g_free(err_str);
exit(2);
ret_val = INVALID_CAPABILITY;
goto clean_exit;
}
if (caps->data_link_types == NULL) {
cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
exit(2);
ret_val = INVALID_LINK_TYPE;
goto clean_exit;
}
#ifdef _WIN32
create_console();
@ -724,7 +731,8 @@ int main(int argc, char *qt_argv[])
free_if_capabilities(caps);
}
}
exit(0);
ret_val = EXIT_SUCCESS;
goto clean_exit;
}
capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
@ -817,7 +825,6 @@ int main(int argc, char *qt_argv[])
////////
gchar* err_msg = NULL;
if (!color_filters_init(&err_msg, color_filter_add_cb)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
g_free(err_msg);
@ -935,6 +942,8 @@ int main(int argc, char *qt_argv[])
destroy_console();
#endif /* _WIN32 */
clean_exit:
capture_opts_cleanup(&global_capture_opts);
return ret_val;
}