aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Kukawka <danny.kukawka@web.de>2008-03-11 18:00:13 +0100
committerDanny Kukawka <danny.kukawka@web.de>2008-03-11 18:00:13 +0100
commit88fd8cd367e39ad916bd59f4fcc8735c87426cef (patch)
tree35759f884ddbe1af2232fbea5fc0e83514d87167
parentre-remove deprecated keys (diff)
downloadgentoo-hal-88fd8cd367e39ad916bd59f4fcc8735c87426cef.tar.gz
gentoo-hal-88fd8cd367e39ad916bd59f4fcc8735c87426cef.tar.bz2
gentoo-hal-88fd8cd367e39ad916bd59f4fcc8735c87426cef.zip
fixed possible segfault from fd.o bug #14947
Fixed possible segfault from fd.o bug #14947 for the case that the remaining time is over 60 hours and the chargeRate was never before 0 or the rate was never guessed which means saved_battery_info wasn't initialised.
-rw-r--r--hald/util_pm.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/hald/util_pm.c b/hald/util_pm.c
index 72fa9f5c..e630461e 100644
--- a/hald/util_pm.c
+++ b/hald/util_pm.c
@@ -143,10 +143,8 @@ util_compute_time_remaining (const char *id,
chargeRate = battery_info->last_chargeRate;
} else {
chargeRate = ((chargeLevel - battery_info->last_level) * 60 * 60) / (cur_time - battery_info->last_time);
- /*
- * During discharging chargeRate would be negative, which would
- * mess up the the calculation below, so we make sure it's always
- * positive.
+ /* During discharging chargeRate would be negative, which would mess
+ * up the the calculation below, so we make sure it's always positive.
*/
chargeRate = (chargeRate > 0) ? chargeRate : -chargeRate;
@@ -192,6 +190,10 @@ util_compute_time_remaining (const char *id,
else if (remaining_time > 60*60*60) {
batteryInfo *battery_info;
+ /* to be sure saved_battery_info is initialised */
+ if (!saved_battery_info)
+ saved_battery_info = g_hash_table_new(g_str_hash, g_str_equal);
+
if (!(battery_info = g_hash_table_lookup(saved_battery_info, id))) {
battery_info = g_new0(batteryInfo, 1);
g_hash_table_insert(saved_battery_info, (char*) id, battery_info);