summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2009-09-11 14:08:08 +0100
committerRichard Hughes <richard@hughsie.com>2009-09-11 14:08:08 +0100
commita09005a0a3a61537e8f34a0db2fec990a5333bd4 (patch)
tree9343da7c02ea0ad499eff73958893cf26ba8f9fd
parent9785f18d7e8ba0c927b52fbfba0147a4afdaf28f (diff)
Be more militant with refcount checking to prevent crashes
-rw-r--r--src/dkp-daemon.c18
-rw-r--r--src/dkp-device-list.c7
-rw-r--r--src/dkp-qos.c2
-rw-r--r--src/linux/dkp-backend.c3
-rw-r--r--src/linux/dkp-device-supply.c12
5 files changed, 34 insertions, 8 deletions
diff --git a/src/dkp-daemon.c b/src/dkp-daemon.c
index 7c91b6c..2621926 100644
--- a/src/dkp-daemon.c
+++ b/src/dkp-daemon.c
@@ -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);
}
diff --git a/src/dkp-device-list.c b/src/dkp-device-list.c
index c8b9ab0..4b31c38 100644
--- a/src/dkp-device-list.c
+++ b/src/dkp-device-list.c
@@ -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;
}
diff --git a/src/dkp-qos.c b/src/dkp-qos.c
index 2a453d7..35b2ce0 100644
--- a/src/dkp-qos.c
+++ b/src/dkp-qos.c
@@ -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 */
diff --git a/src/linux/dkp-backend.c b/src/linux/dkp-backend.c
index 33c45bf..e5c630a 100644
--- a/src/linux/dkp-backend.c
+++ b/src/linux/dkp-backend.c
@@ -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;
}
diff --git a/src/linux/dkp-device-supply.c b/src/linux/dkp-device-supply.c
index 56f873a..fd759ec 100644
--- a/src/linux/dkp-device-supply.c
+++ b/src/linux/dkp-device-supply.c
@@ -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;
}