[gnome-control-center/gnome-3-8] power: Fix crash with no batteries
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gnome-3-8] power: Fix crash with no batteries
- Date: Fri, 19 Jul 2013 07:40:12 +0000 (UTC)
commit 026d7790d8f14b6611b4b89157b6cb61cdb0ab7f
Author: Bastien Nocera <hadess hadess net>
Date: Fri Jul 19 09:36:43 2013 +0200
power: Fix crash with no batteries
https://bugzilla.gnome.org/show_bug.cgi?id=704486
panels/power/cc-power-panel.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index 6c56b04..d70496a 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -700,7 +700,7 @@ up_client_changed (UpClient *client,
"power-supply", TRUE,
"is-present", TRUE,
NULL);
- for (i = 0; i < devices->len; i++)
+ for (i = 0; devices != NULL && i < devices->len; i++)
{
UpDevice *device = (UpDevice*) g_ptr_array_index (devices, i);
g_object_get (device,
@@ -767,7 +767,7 @@ up_client_changed (UpClient *client,
if (!on_ups && n_batteries > 1)
set_primary (self, composite);
- for (i = 0; i < devices->len; i++)
+ for (i = 0; devices != NULL && i < devices->len; i++)
{
UpDevice *device = (UpDevice*) g_ptr_array_index (devices, i);
g_object_get (device, "kind", &kind, NULL);
@@ -793,7 +793,7 @@ up_client_changed (UpClient *client,
}
}
- g_ptr_array_unref (devices);
+ g_clear_pointer (&devices, g_ptr_array_unref);
g_object_unref (composite);
}
@@ -1041,7 +1041,7 @@ set_ac_battery_ui_mode (CcPowerPanel *self)
devices = up_client_get_devices (self->priv->up_client);
g_debug ("got %d devices from upower\n", devices->len);
- for (i = 0; i < devices->len; i++)
+ for (i = 0; devices != NULL && i < devices->len; i++)
{
device = g_ptr_array_index (devices, i);
g_object_get (device, "kind", &kind, NULL);
@@ -1051,7 +1051,7 @@ set_ac_battery_ui_mode (CcPowerPanel *self)
break;
}
}
- g_ptr_array_unref (devices);
+ g_clear_pointer (&devices, g_ptr_array_unref);
#ifdef TEST_NO_BATTERIES
g_print ("forcing no batteries\n");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]