diff options
author | Pascal Quantin <pascal.quantin@gmail.com> | 2015-06-17 19:55:19 +0200 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-06-17 23:24:58 +0000 |
commit | 60f33b658190ea4d016f3cb535199d15e14d2d87 (patch) | |
tree | 8822853e4646c8727ca5704873b8b125a0af3627 /wireshark-qt.cpp | |
parent | d5f1ae709b95a81dcfb26eea921d50a5b1979278 (diff) |
Qt: fix a crash when closing application under Windows
QCoreApplication visits eldritch horrors upon argv on Windows. Keep a
local copy for our own processing.
---
[ Pascal's original comments ]
g6c4ec4a introduced the use of arg_list_utf_16to8 that triggers a crash on my
computer when freeing the g_allocated memory.
Let's do a similar work but with a memory allocator that does not trigger an exception.
Also fix a memory leak in arg_list_utf_16to8 while we are at it.
Change-Id: I93d899af20b09c9a5d584a46297f715591502df9
Reviewed-on: https://code.wireshark.org/review/8961
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wireshark-qt.cpp')
-rw-r--r-- | wireshark-qt.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index 4fdb22d15c..4640944a8c 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -433,6 +433,7 @@ int main(int argc, char *argv[]) int opt; gboolean arg_error = FALSE; + char **ws_argv = argv; #ifdef _WIN32 WSADATA wsaData; @@ -478,7 +479,12 @@ int main(int argc, char *argv[]) // The GTK+ UI calls this. Should we as well? //setlocale(LC_ALL, ""); #ifdef _WIN32 - arg_list_utf_16to8(argc, argv); + // QCoreApplication clobbers argv. Let's have a local copy. + ws_argv = (char **) g_malloc(sizeof(char *) * argc); + for (opt = 0; opt < argc; opt++) { + ws_argv[opt] = argv[opt]; + } + arg_list_utf_16to8(argc, ws_argv); create_app_running_mutex(); #endif /* _WIN32 */ @@ -493,7 +499,7 @@ int main(int argc, char *argv[]) /* * Attempt to get the pathname of the executable file. */ - /* init_progfile_dir_error = */ init_progfile_dir(argv[0], + /* init_progfile_dir_error = */ init_progfile_dir(ws_argv[0], (void *) get_gui_compiled_info); g_log(NULL, G_LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir()); @@ -556,7 +562,7 @@ DIAG_ON(cast-qual) opterr = 0; - while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, ws_argv, optstring, long_options, NULL)) != -1) { switch (opt) { case 'C': /* Configuration Profile */ if (profile_exists (optarg, FALSE)) { @@ -875,7 +881,7 @@ DIAG_ON(cast-qual) opterr = 1; /* Now get our args */ - while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, ws_argv, optstring, long_options, NULL)) != -1) { switch (opt) { /*** capture option specific ***/ case 'a': /* autostop criteria */ @@ -1090,7 +1096,7 @@ DIAG_ON(cast-qual) if (!arg_error) { argc -= optind; - argv += optind; + ws_argv += optind; if (argc >= 1) { if (!cf_name.isEmpty()) { /* @@ -1110,18 +1116,18 @@ DIAG_ON(cast-qual) * file - yes, you could have "-r" as the last part of the command, * but that's a bit ugly. */ - cf_name = argv[0]; + cf_name = ws_argv[0]; } argc--; - argv++; + ws_argv++; } if (argc != 0) { /* * Extra command line arguments were specified; complain. */ - cmdarg_err("Invalid argument: %s", argv[0]); + cmdarg_err("Invalid argument: %s", ws_argv[0]); arg_error = TRUE; } } |