summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-03-09 17:10:20 +0100
committerThomas Haller <thaller@redhat.com>2020-03-16 13:40:51 +0100
commite0e39a745256204a2ac4727f84cc5d2ea684c70f (patch)
treee0c8e28669e7609cbcece5fa9ef02d1cba15ec9c
parentca4b5307426bc93e4df03aca62fc8182de27765b (diff)
downloadNetworkManager-e0e39a745256204a2ac4727f84cc5d2ea684c70f.tar.gz
cli: take reference in sort_access_points() for "clients/cli/devices.c"
It's not really necessary, but it feels slightly more correct. The only reason not to take a reference is to safe the overhead of increasing and decreasing the reference counter. But that doesn't matter for nmcli at this point (and is tiny anyway). Let the API make sure that the instances are kept alive.
-rw-r--r--clients/cli/devices.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index 302ab0f18a..5c18f7cf76 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -1117,13 +1117,14 @@ static GPtrArray *
sort_access_points (const GPtrArray *aps)
{
GPtrArray *sorted;
- int i;
+ guint i;
g_return_val_if_fail (aps, NULL);
sorted = g_ptr_array_sized_new (aps->len);
+ g_ptr_array_set_free_func (sorted, nm_g_object_unref);
for (i = 0; i < aps->len; i++)
- g_ptr_array_add (sorted, aps->pdata[i]);
+ g_ptr_array_add (sorted, g_object_ref (aps->pdata[i]));
g_ptr_array_sort_with_data (sorted, compare_aps, NULL);
return sorted;
}
@@ -1542,7 +1543,6 @@ show_device_info (NMDevice *device, NmCli *nmc)
if ((NM_IS_DEVICE_WIFI (device))) {
NMAccessPoint *active_ap = NULL;
const char *active_bssid = NULL;
- GPtrArray *aps;
/* section AP */
if (!g_ascii_strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[4]->name)) {
@@ -1560,6 +1560,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
g_ptr_array_add (out.output_data, arr);
{
+ gs_unref_ptrarray GPtrArray *aps = NULL;
APInfo info = {
.nmc = nmc,
.index = 1,
@@ -1571,7 +1572,6 @@ show_device_info (NMDevice *device, NmCli *nmc)
aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)));
g_ptr_array_foreach (aps, fill_output_access_point, &info);
- g_ptr_array_free (aps, FALSE);
}
print_data_prepare_width (out.output_data);
@@ -2784,7 +2784,6 @@ show_access_point_info (NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out)
{
NMAccessPoint *active_ap = NULL;
const char *active_bssid = NULL;
- GPtrArray *aps;
NmcOutputField *arr;
if (nm_device_get_state (NM_DEVICE (wifi)) == NM_DEVICE_STATE_ACTIVATED) {
@@ -2797,6 +2796,7 @@ show_access_point_info (NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out)
g_ptr_array_add (out->output_data, arr);
{
+ gs_unref_ptrarray GPtrArray *aps = NULL;
APInfo info = {
.nmc = nmc,
.index = 1,
@@ -2808,7 +2808,6 @@ show_access_point_info (NMDeviceWifi *wifi, NmCli *nmc, NmcOutputData *out)
aps = sort_access_points (nm_device_wifi_get_access_points (wifi));
g_ptr_array_foreach (aps, fill_output_access_point, &info);
- g_ptr_array_free (aps, TRUE);
}
print_data_prepare_width (out->output_data);