mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-05 05:18:00 +02:00
Be more militant with refcount checking to prevent crashes
This commit is contained in:
parent
9785f18d7e
commit
a09005a0a3
5 changed files with 34 additions and 8 deletions
|
|
@ -603,6 +603,12 @@ dkp_daemon_device_added_cb (DkpBackend *backend, GObject *native, DkpDevice *dev
|
|||
if (!daemon->priv->during_coldplug) {
|
||||
object_path = dkp_device_get_object_path (device);
|
||||
egg_debug ("emitting added: %s (during coldplug %i)", object_path, daemon->priv->during_coldplug);
|
||||
|
||||
/* don't crash the session */
|
||||
if (object_path == NULL) {
|
||||
egg_warning ("INTERNAL STATE CORRUPT: not sending NULL, native:%p, device:%p", native, device);
|
||||
return;
|
||||
}
|
||||
g_signal_emit (daemon, signals[SIGNAL_DEVICE_ADDED], 0, object_path);
|
||||
}
|
||||
}
|
||||
|
|
@ -649,6 +655,12 @@ dkp_daemon_device_changed_cb (DkpBackend *backend, GObject *native, DkpDevice *d
|
|||
if (!daemon->priv->during_coldplug) {
|
||||
object_path = dkp_device_get_object_path (device);
|
||||
egg_debug ("emitting device-changed: %s", object_path);
|
||||
|
||||
/* don't crash the session */
|
||||
if (object_path == NULL) {
|
||||
egg_warning ("INTERNAL STATE CORRUPT: not sending NULL, native:%p, device:%p", native, device);
|
||||
return;
|
||||
}
|
||||
g_signal_emit (daemon, signals[SIGNAL_DEVICE_CHANGED], 0, object_path);
|
||||
}
|
||||
}
|
||||
|
|
@ -672,6 +684,12 @@ dkp_daemon_device_removed_cb (DkpBackend *backend, GObject *native, DkpDevice *d
|
|||
if (!daemon->priv->during_coldplug) {
|
||||
object_path = dkp_device_get_object_path (device);
|
||||
egg_debug ("emitting device-removed: %s", object_path);
|
||||
|
||||
/* don't crash the session */
|
||||
if (object_path == NULL) {
|
||||
egg_warning ("INTERNAL STATE CORRUPT: not sending NULL, native:%p, device:%p", native, device);
|
||||
return;
|
||||
}
|
||||
g_signal_emit (daemon, signals[SIGNAL_DEVICE_REMOVED], 0, object_path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,6 +121,13 @@ dkp_device_list_remove (DkpDeviceList *list, GObject *device)
|
|||
g_hash_table_foreach_remove (list->priv->map_native_path_to_device,
|
||||
dkp_device_list_remove_cb, device);
|
||||
g_ptr_array_remove (list->priv->array, device);
|
||||
|
||||
/* we're removed the last instance? */
|
||||
if (!G_IS_OBJECT (device)) {
|
||||
egg_warning ("INTERNAL STATE CORRUPT: we've removed the last instance of %p", device);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ dkp_qos_set_minimum_latency (DkpQos *qos, const gchar *type_text, gint value, DB
|
|||
return;
|
||||
}
|
||||
|
||||
egg_warning ("setting %s minimum to %i", type_text, value);
|
||||
egg_debug ("setting %s minimum to %i", type_text, value);
|
||||
qos->priv->minimum[type] = value;
|
||||
|
||||
/* may have changed */
|
||||
|
|
|
|||
|
|
@ -217,7 +217,6 @@ dkp_backend_device_add (DkpBackend *backend, GUdevDevice *native)
|
|||
|
||||
/* emit */
|
||||
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, native, device);
|
||||
g_object_unref (device);
|
||||
out:
|
||||
if (object != NULL)
|
||||
g_object_unref (object);
|
||||
|
|
@ -236,7 +235,7 @@ dkp_backend_device_remove (DkpBackend *backend, GUdevDevice *native)
|
|||
/* does device exist in db? */
|
||||
object = dkp_device_list_lookup (backend->priv->device_list, G_OBJECT (native));
|
||||
if (object == NULL) {
|
||||
egg_warning ("ignoring remove event on %s", g_udev_device_get_sysfs_path (native));
|
||||
egg_debug ("ignoring remove event on %s", g_udev_device_get_sysfs_path (native));
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
/* some batteries stop charging much before 100% */
|
||||
if (state == DKP_DEVICE_STATE_UNKNOWN &&
|
||||
percentage > DKP_DEVICE_SUPPLY_CHARGED_THRESHOLD) {
|
||||
egg_warning ("fixing up unknown %f", percentage);
|
||||
egg_debug ("fixing up unknown %f", percentage);
|
||||
state = DKP_DEVICE_STATE_FULLY_CHARGED;
|
||||
}
|
||||
|
||||
|
|
@ -628,7 +628,7 @@ static gboolean
|
|||
dkp_device_supply_coldplug (DkpDevice *device)
|
||||
{
|
||||
DkpDeviceSupply *supply = DKP_DEVICE_SUPPLY (device);
|
||||
gboolean ret;
|
||||
gboolean ret = FALSE;
|
||||
GUdevDevice *native;
|
||||
const gchar *native_path;
|
||||
|
||||
|
|
@ -637,8 +637,10 @@ dkp_device_supply_coldplug (DkpDevice *device)
|
|||
/* detect what kind of device we are */
|
||||
native = G_UDEV_DEVICE (dkp_device_get_native (device));
|
||||
native_path = g_udev_device_get_sysfs_path (native);
|
||||
if (native_path == NULL)
|
||||
egg_error ("could not get native path");
|
||||
if (native_path == NULL) {
|
||||
egg_warning ("could not get native path for %p", device);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (sysfs_file_exists (native_path, "online")) {
|
||||
g_object_set (device, "type", DKP_DEVICE_TYPE_LINE_POWER, NULL);
|
||||
|
|
@ -649,7 +651,7 @@ dkp_device_supply_coldplug (DkpDevice *device)
|
|||
|
||||
/* coldplug values */
|
||||
ret = dkp_device_supply_refresh (device);
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue