nmcli: fix some leaks found by valgrind

https://bugzilla.gnome.org/show_bug.cgi?id=709369
This commit is contained in:
Dan Winship
2013-10-03 10:08:22 -04:00
parent 00ffb78c8d
commit 0221971da5
3 changed files with 19 additions and 17 deletions

View File

@@ -383,7 +383,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
} }
if (print_settings_array) if (print_settings_array)
g_array_free (print_settings_array, FALSE); g_array_free (print_settings_array, TRUE);
return TRUE; return TRUE;
} }
@@ -472,8 +472,6 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
char *fields_str; char *fields_str;
char *fields_all = NMC_FIELDS_CON_SHOW_ALL; char *fields_all = NMC_FIELDS_CON_SHOW_ALL;
char *fields_common = NMC_FIELDS_CON_SHOW_COMMON; char *fields_common = NMC_FIELDS_CON_SHOW_COMMON;
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
gboolean printed = FALSE; gboolean printed = FALSE;
nmc->should_wait = FALSE; nmc->should_wait = FALSE;
@@ -485,16 +483,17 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
else else
fields_str = nmc->required_fields; fields_str = nmc->required_fields;
tmpl = nmc_fields_con_show;
tmpl_len = sizeof (nmc_fields_con_show);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error1);
/* error1 is checked later - it's not valid for connection details */
if (argc == 0) { if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error2)) NmcOutputField *tmpl, *arr;
goto error; size_t tmpl_len;
tmpl = nmc_fields_con_show;
tmpl_len = sizeof (nmc_fields_con_show);
nmc->print_fields.indices = parse_output_fields (fields_str, tmpl, &error1);
if (error1) if (error1)
goto error; goto error;
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error2))
goto error;
/* Add headers */ /* Add headers */
nmc->print_fields.header_name = _("List of configured connections"); nmc->print_fields.header_name = _("List of configured connections");
@@ -505,8 +504,6 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
g_slist_foreach (nmc->system_connections, fill_output_connection, nmc); g_slist_foreach (nmc->system_connections, fill_output_connection, nmc);
print_data (nmc); /* Print all data */ print_data (nmc); /* Print all data */
} else { } else {
g_clear_error (&error1); /* the error1 is only relevant for 'show configured' without arguments */
while (argc > 0) { while (argc > 0) {
NMConnection *con; NMConnection *con;
const char *selector = NULL; const char *selector = NULL;
@@ -976,7 +973,7 @@ nmc_active_connection_detail (NMActiveConnection *acon, NmCli *nmc)
} }
if (print_groups) if (print_groups)
g_array_free (print_groups, FALSE); g_array_free (print_groups, TRUE);
return TRUE; return TRUE;
} }
@@ -1399,7 +1396,7 @@ progress_vpn_cb (gpointer user_data)
typedef struct { typedef struct {
NmCli *nmc; NmCli *nmc;
NMDevice *device; NMDevice *device;
const char *con_type; char *con_type;
} ActivateConnectionInfo; } ActivateConnectionInfo;
static gboolean static gboolean
@@ -1428,6 +1425,7 @@ master_iface_slaves_check (gpointer user_data)
quit (); quit ();
} }
g_free (info->con_type);
g_free (info); g_free (info);
return FALSE; return FALSE;
} }
@@ -1497,6 +1495,7 @@ activate_connection_cb (NMClient *client, NMActiveConnection *active, GError *er
} }
} }
} }
g_free (info->con_type);
g_free (info); g_free (info);
} }
@@ -1638,7 +1637,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
info = g_malloc0 (sizeof (ActivateConnectionInfo)); info = g_malloc0 (sizeof (ActivateConnectionInfo));
info->nmc = nmc; info->nmc = nmc;
info->device = device; info->device = device;
info->con_type = con_type; info->con_type = g_strdup (con_type);
nm_client_activate_connection (nmc->client, nm_client_activate_connection (nmc->client,
connection, connection,

View File

@@ -388,8 +388,6 @@ nmc_cleanup (NmCli *nmc)
g_free (nmc->required_fields); g_free (nmc->required_fields);
nmc_empty_output_fields (nmc); nmc_empty_output_fields (nmc);
g_ptr_array_unref (nmc->output_data); g_ptr_array_unref (nmc->output_data);
if (nmc->print_fields.indices)
g_array_free (nmc->print_fields.indices, TRUE);
} }
static gboolean static gboolean

View File

@@ -696,6 +696,11 @@ nmc_empty_output_fields (NmCli *nmc)
/* Empty output_data array */ /* Empty output_data array */
if (nmc->output_data->len > 0) if (nmc->output_data->len > 0)
g_ptr_array_remove_range (nmc->output_data, 0, nmc->output_data->len); g_ptr_array_remove_range (nmc->output_data, 0, nmc->output_data->len);
if (nmc->print_fields.indices) {
g_array_free (nmc->print_fields.indices, TRUE);
nmc->print_fields.indices = NULL;
}
} }
static char * static char *