mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-01-30 05:50:25 +01:00
Fix a small memory leak on supply coldplugging
This commit is contained in:
parent
3894b36273
commit
e66bc06cfd
1 changed files with 41 additions and 4 deletions
|
|
@ -274,6 +274,31 @@ dkp_device_supply_convert_device_technology (const gchar *type)
|
|||
return DKP_DEVICE_TECHNOLOGY_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_supply_get_string:
|
||||
**/
|
||||
static gchar *
|
||||
dkp_device_supply_get_string (const gchar *native_path, const gchar *key)
|
||||
{
|
||||
gchar *value;
|
||||
|
||||
/* get value, and strip to remove spaces */
|
||||
value = g_strstrip (sysfs_get_string (native_path, key));
|
||||
|
||||
/* no value */
|
||||
if (value == NULL)
|
||||
goto out;
|
||||
|
||||
/* empty value */
|
||||
if (value[0] == '\0') {
|
||||
g_free (value);
|
||||
value = NULL;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_supply_refresh_battery:
|
||||
*
|
||||
|
|
@ -301,6 +326,9 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
gdouble voltage;
|
||||
guint64 time_to_empty;
|
||||
guint64 time_to_full;
|
||||
gchar *manufacturer;
|
||||
gchar *model_name;
|
||||
gchar *serial_number;
|
||||
|
||||
d = dkp_device_get_d (device);
|
||||
if (d == NULL) {
|
||||
|
|
@ -341,19 +369,28 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
g_object_set (device, "power-supply", TRUE, NULL);
|
||||
|
||||
/* the ACPI spec is bad at defining battery type constants */
|
||||
technology_native = g_strstrip (sysfs_get_string (native_path, "technology"));
|
||||
technology_native = dkp_device_supply_get_string (native_path, "technology");
|
||||
g_object_set (device, "technology", dkp_device_supply_convert_device_technology (technology_native), NULL);
|
||||
g_free (technology_native);
|
||||
|
||||
/* get values which may be blank */
|
||||
manufacturer = dkp_device_supply_get_string (native_path, "manufacturer");
|
||||
model_name = dkp_device_supply_get_string (native_path, "model_name");
|
||||
serial_number = dkp_device_supply_get_string (native_path, "serial_number");
|
||||
|
||||
g_object_set (device,
|
||||
"vendor", g_strstrip (sysfs_get_string (native_path, "manufacturer")),
|
||||
"model", g_strstrip (sysfs_get_string (native_path, "model_name")),
|
||||
"serial", g_strstrip (sysfs_get_string (native_path, "serial_number")),
|
||||
"vendor", manufacturer,
|
||||
"model", model_name,
|
||||
"serial", serial_number,
|
||||
"is-rechargeable", TRUE, /* assume true for laptops */
|
||||
"has-history", TRUE,
|
||||
"has-statistics", TRUE,
|
||||
NULL);
|
||||
|
||||
g_free (manufacturer);
|
||||
g_free (model_name);
|
||||
g_free (serial_number);
|
||||
|
||||
/* these don't change at runtime */
|
||||
energy_full = sysfs_get_double (native_path, "energy_full") / 1000000.0;
|
||||
energy_full_design = sysfs_get_double (native_path, "energy_full_design") / 1000000.0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue