[banshee] osx: avoid possible NREs when firing device events
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] osx: avoid possible NREs when firing device events
- Date: Sun, 21 Jun 2015 18:41:54 +0000 (UTC)
commit 7513dcdd9c62aeb64a781127d1cf1a3225fa4322
Author: Andrés G. Aragoneses <knocte gmail com>
Date: Sun Jun 21 20:41:44 2015 +0200
osx: avoid possible NREs when firing device events
The launch of these events was not protected with null checks,
something which could potentially lead to NullReferenceExceptions
if there were no observers for this events.
.../Banshee.OsxBackend/HardwareManager.cs | 24 +++++++++++++++-----
1 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/Backends/Banshee.Osx/Banshee.OsxBackend/HardwareManager.cs
b/src/Backends/Banshee.Osx/Banshee.OsxBackend/HardwareManager.cs
index 37af6db..0c10651 100644
--- a/src/Backends/Banshee.Osx/Banshee.OsxBackend/HardwareManager.cs
+++ b/src/Backends/Banshee.Osx/Banshee.OsxBackend/HardwareManager.cs
@@ -44,7 +44,7 @@ namespace Banshee.OsxBackend
public sealed class HardwareManager : IHardwareManager, IService
{
public event DeviceAddedHandler DeviceAdded;
- public event DeviceChangedHandler DeviceChanged;
+ public event DeviceChangedHandler DeviceChanged;
public event DeviceRemovedHandler DeviceRemoved;
private List<IDevice> devices = new List<IDevice> ();
@@ -91,8 +91,11 @@ namespace Banshee.OsxBackend
if (new_device != null) {
devices.Add (new_device);
- // Notify that a device was added (i.e. to refresh device list)
- DeviceAdded (this, new DeviceAddedArgs ((IDevice) new_device));
+ var added_handler = DeviceAdded;
+ if (added_handler != null) {
+ // Notify that a device was added (i.e. to refresh device list)
+ added_handler (this, new DeviceAddedArgs ((IDevice)new_device));
+ }
}
}
}
@@ -110,7 +113,10 @@ namespace Banshee.OsxBackend
// a device that was currently attached has changed
// remove the device and immediately re-add it
devices.Remove (old_device);
- DeviceRemoved (old_device, new DeviceRemovedArgs (old_device.Uuid));
+ var remove_handler = DeviceRemoved;
+ if (remove_handler != null) {
+ remove_handler (old_device, new DeviceRemovedArgs (old_device.Uuid));
+ }
}
// do not add device without a VolumePath (=MountPoint)
@@ -126,7 +132,10 @@ namespace Banshee.OsxBackend
new_device = new Volume (args);
}
devices.Add (new_device);
- DeviceAdded (this, new DeviceAddedArgs ((IDevice) new_device));
+ var added_handler = DeviceAdded;
+ if (added_handler != null) {
+ added_handler (this, new DeviceAddedArgs ((IDevice)new_device));
+ }
}
}
@@ -141,7 +150,10 @@ namespace Banshee.OsxBackend
var old_device = devices.Where (d => d.Uuid == device.Uuid).FirstOrDefault ();
if (old_device != null) {
devices.Remove (old_device);
- DeviceRemoved (this, new DeviceRemovedArgs (old_device.Uuid));
+ var removed_handler = DeviceRemoved;
+ if (removed_handler != null) {
+ removed_handler (this, new DeviceRemovedArgs (old_device.Uuid));
+ }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]