Update capture_opts in extcap_cleanup().

This fixes redundant extcap_pid handle close that could occur in
capture_opts_del_iface() which resulted in unhandled exception on
Windows.

Change-Id: I06b680fcb65cd6fd854a25fb1b01248dce3251a1
Reviewed-on: https://code.wireshark.org/review/4447
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Roland Knall <rknall@gmail.com>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
This commit is contained in:
Tomasz Moń 2014-10-03 19:27:04 +02:00 committed by Pascal Quantin
parent 06926aed88
commit 20795925ff
3 changed files with 23 additions and 27 deletions

View File

@ -70,7 +70,7 @@ capture_opts_init(capture_options *capture_opts)
capture_opts->default_options.extcap = NULL;
capture_opts->default_options.extcap_fifo = NULL;
capture_opts->default_options.extcap_args = NULL;
capture_opts->default_options.extcap_pid = (GPid)-1;
capture_opts->default_options.extcap_pid = INVALID_EXTCAP_PID;
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
capture_opts->default_options.buffer_size = DEFAULT_CAPTURE_BUFFER_SIZE;
@ -610,7 +610,7 @@ capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str
interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
interface_opts.extcap_fifo = g_strdup(capture_opts->default_options.extcap_fifo);
interface_opts.extcap_args = NULL;
interface_opts.extcap_pid = (GPid)-1;
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = capture_opts->default_options.buffer_size;
@ -1046,7 +1046,7 @@ capture_opts_del_iface(capture_options *capture_opts, guint if_index)
g_free(interface_opts.extcap_fifo);
if (interface_opts.extcap_args)
g_hash_table_unref(interface_opts.extcap_args);
if (interface_opts.extcap_pid > 0)
if (interface_opts.extcap_pid != INVALID_EXTCAP_PID)
g_spawn_close_pid(interface_opts.extcap_pid);
#endif
#ifdef HAVE_PCAP_REMOTE
@ -1094,7 +1094,7 @@ collect_ifaces(capture_options *capture_opts)
interface_opts.extcap = g_strdup(device.if_info.extcap);
interface_opts.extcap_fifo = NULL;
interface_opts.extcap_args = device.external_cap_args_settings;
interface_opts.extcap_pid = (GPid)-1;
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
if (interface_opts.extcap_args)
g_hash_table_ref(interface_opts.extcap_args);
#endif

View File

@ -206,6 +206,12 @@ typedef struct link_row_tag {
gint dlt;
} link_row;
#ifdef WIN32
#define INVALID_EXTCAP_PID INVALID_HANDLE_VALUE
#else
#define INVALID_EXTCAP_PID (GPid)-1
#endif
typedef struct interface_options_tag {
gchar *name; /* the name of the interface provided to winpcap/libpcap to specify the interface */
gchar *descr;
@ -220,7 +226,7 @@ typedef struct interface_options_tag {
gchar *extcap;
gchar *extcap_fifo;
GHashTable *extcap_args;
GPid extcap_pid;
GPid extcap_pid; /* pid of running process or INVALID_EXTCAP_PID */
guint extcap_child_watch;
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)

View File

@ -434,20 +434,18 @@ void extcap_cleanup(capture_options * capture_opts) {
interface_opts.extcap_child_watch = 0;
}
if (interface_opts.extcap_pid != INVALID_EXTCAP_PID)
{
#ifdef WIN32
if (interface_opts.extcap_pid != INVALID_HANDLE_VALUE)
{
TerminateProcess(interface_opts.extcap_pid, 0);
g_spawn_close_pid(interface_opts.extcap_pid);
interface_opts.extcap_pid = INVALID_HANDLE_VALUE;
}
#else
if (interface_opts.extcap_pid != (GPid)-1 )
{
g_spawn_close_pid(interface_opts.extcap_pid);
interface_opts.extcap_pid = (GPid)-1;
}
#endif
g_spawn_close_pid(interface_opts.extcap_pid);
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
}
/* Make sure modified interface_opts is saved in capture_opts. */
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, icnt);
g_array_insert_val(capture_opts->ifaces, icnt, interface_opts);
}
}
@ -479,11 +477,7 @@ static void extcap_child_watch_cb(GPid pid, gint status _U_, gpointer user_data)
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
if (interface_opts.extcap_pid == pid)
{
#ifdef WIN32
interface_opts.extcap_pid = INVALID_HANDLE_VALUE;
#else
interface_opts.extcap_pid = (GPid)-1;
#endif
interface_opts.extcap_pid = INVALID_EXTCAP_PID;
interface_opts.extcap_child_watch = 0;
capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
g_array_insert_val(capture_opts->ifaces, i, interface_opts);
@ -503,11 +497,7 @@ extcaps_init_initerfaces(capture_options *capture_opts)
for (i = 0; i < capture_opts->ifaces->len; i++)
{
GPtrArray *args = NULL;
#ifdef WIN32
GPid pid = INVALID_HANDLE_VALUE;
#else
GPid pid = 0;
#endif
GPid pid = INVALID_EXTCAP_PID;
gchar **tmp;
int tmp_i;
@ -566,7 +556,7 @@ extcaps_init_initerfaces(capture_options *capture_opts)
*
* Minimum supported version of Windows: XP / Server 2003.
*/
if (pid != INVALID_HANDLE_VALUE)
if (pid != INVALID_EXTCAP_PID)
{
DWORD dw;
HANDLE handles[2];