extcap: Fix a potential leak of memory pointed to by 'toolbar_entry'

Initialize toolbar_entry after error checking is done to avoid a
potential memory leak when exiting early from cb_load_interfaces().

Change-Id: I925d9296085964c6d5c3a9ccae85137285bf9220
Reviewed-on: https://code.wireshark.org/review/28060
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Stig Bjørlykke 2018-06-06 14:01:06 +02:00 committed by Roland Knall
parent e8493fa7c4
commit 26be931810

View File

@ -1648,12 +1648,6 @@ static gboolean cb_load_interfaces(extcap_callback_info_t cb_info)
/* Load interfaces from utility */ /* Load interfaces from utility */
interfaces = extcap_parse_interfaces(cb_info.output, &control_items); interfaces = extcap_parse_interfaces(cb_info.output, &control_items);
if (control_items)
{
toolbar_entry = g_new0(iface_toolbar, 1);
toolbar_entry->controls = control_items;
}
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Loading interface list for %s ", cb_info.extcap); g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Loading interface list for %s ", cb_info.extcap);
/* Seems, that there where no interfaces to be loaded */ /* Seems, that there where no interfaces to be loaded */
@ -1680,6 +1674,12 @@ static gboolean cb_load_interfaces(extcap_callback_info_t cb_info)
return FALSE; return FALSE;
} }
if (control_items)
{
toolbar_entry = g_new0(iface_toolbar, 1);
toolbar_entry->controls = control_items;
}
walker = interfaces; walker = interfaces;
gchar* help = NULL; gchar* help = NULL;
while (walker != NULL) while (walker != NULL)