diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-03-26 18:33:40 -0700 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-03-26 18:33:40 -0700 |
commit | afb59cd4a8fa5731b5f737a4ef58fe1f3ae2fbb8 (patch) | |
tree | 866ee0d2ac1527cba30aee92bfd498b3205f27d3 /src | |
parent | e02ed10f6b14e5d43a6e02e0ea929a71cfba5964 (diff) | |
download | ayatana-indicator-sound-afb59cd4a8fa5731b5f737a4ef58fe1f3ae2fbb8.tar.gz ayatana-indicator-sound-afb59cd4a8fa5731b5f737a4ef58fe1f3ae2fbb8.tar.bz2 ayatana-indicator-sound-afb59cd4a8fa5731b5f737a4ef58fe1f3ae2fbb8.zip |
prevent a cyclical dependency in establish_file_monitoring() from trying to unref 'monitor' right after it's been freed.
Diffstat (limited to 'src')
-rw-r--r-- | src/music-player-bridge.vala | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index c2d6623..18f1c40 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -85,19 +85,20 @@ public class MusicPlayerBridge : GLib.Object DesktopAppInfo desktop_info = info as DesktopAppInfo; var file_path = desktop_info.get_filename (); File f = File.new_for_path (file_path); - FileMonitor monitor; try { - monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null); + FileMonitor monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null); + unowned FileMonitor weak_monitor = monitor; + monitor.changed.connect ((desktop_file, other_file, event_type) => { + this.relevant_desktop_file_changed (desktop_file, other_file, event_type, weak_monitor); + }); + monitor.ref(); // will be unref()ed by relevant_desktop_file_changed() + GLib.debug ("monitoring file '%s'", file_path); + this.file_monitors.set (file_path, mpris_key); } catch (Error e){ warning ("Unable to create a file monitor for %s", info.get_name()); return; } - this.file_monitors.set (file_path, mpris_key); - // Finally watch for a change. - monitor.changed.connect ((desktop_file, other_file, event_type) => { - this.relevant_desktop_file_changed (desktop_file, other_file, event_type, monitor); - }); } private void relevant_desktop_file_changed (File desktop_file, @@ -117,10 +118,13 @@ public class MusicPlayerBridge : GLib.Object warning ("relevant_desktop_file_changed is returning a file which we know nothing about - %s", path); return; - } - this.registered_clients[this.file_monitors[path]].remove_from_menu(); - this.settings_manager.remove_interested (this.file_monitors[path]); - this.registered_clients.unset (this.file_monitors[path]); + } + + var mpris_key = this.file_monitors[path]; + GLib.debug ("file \"%s\" was removed; stopping monitoring \"%s\"", path, mpris_key); + this.registered_clients[mpris_key].remove_from_menu(); + this.settings_manager.remove_interested (mpris_key); + this.registered_clients.unset (mpris_key); monitor.cancel (); monitor.unref(); } |