Merge lp:~gue5t/midori/tabby-leaks into lp:midori

Proposed by gue5t gue5t
Status: Merged
Approved by: André Stösel
Approved revision: 6676
Merged at revision: 6678
Proposed branch: lp:~gue5t/midori/tabby-leaks
Merge into: lp:midori
Diff against target: 163 lines (+44/-17)
1 file modified
extensions/tabby.vala (+44/-17)
To merge this branch: bzr merge lp:~gue5t/midori/tabby-leaks
Reviewer Review Type Date Requested Status
André Stösel Approve
Review via email: mp+216810@code.launchpad.net

Commit message

Fix leaks of two references to the MidoriApp in Tabby

Description of the change

Tabby seems to assume it will never be deactivated, which is an inherently leaky philosophy. This nulls out at least the two fields that hold references to the MidoriApp when Tabby is (theoretically) deactivated.

To post a comment you must log in.
Revision history for this message
André Stösel (ivaldi) wrote :

Well, this will most likely break things if some event (which is handled by tabby) is triggered after deactivated is called. Yes, you are right, tabby assumes it is never deactivated, but if we change it, we should do it the right way.

review: Needs Fixing
Revision history for this message
gue5t gue5t (gue5t) wrote :

Tabby won't be deactivated in normal use since it's essentially part of the core, but only when the browser is shut down. When Tabby *is* deactivated, it should not hold references to the MidoriApp.

Revision history for this message
André Stösel (ivaldi) wrote :

It doesn't matter - if we do it, we should do it all right!
(There could be some race conditions which triggers some (future) event after the deactivate call and midori could segfault,... you never know ;)

Revision history for this message
gue5t gue5t (gue5t) wrote :

I guess it's fair enough that we should make sure all signals are disconnected first. I'll update the branch when I get a chance.

lp:~gue5t/midori/tabby-leaks updated
6675. By gue5t <email address hidden>

Document vfuncs in tabby and disconnect some signals on deactivation

Revision history for this message
Cris Dywan (kalikiana) wrote :

60 - public virtual void close () {
61 + public void detach () {

Is this intended?

lp:~gue5t/midori/tabby-leaks updated
6676. By gue5t <email address hidden>

Factor detach back into close to avoid extra public API change and keep code simple

Revision history for this message
André Stösel (ivaldi) wrote :

looks good (thx for the comments ;)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'extensions/tabby.vala'
--- extensions/tabby.vala 2014-03-26 00:00:38 +0000
+++ extensions/tabby.vala 2014-04-25 19:50:26 +0000
@@ -16,7 +16,7 @@
1616
17 /* function called from Manager object */17 /* function called from Manager object */
18 public interface IStorage : GLib.Object {18 public interface IStorage : GLib.Object {
19 public abstract Katze.Array get_sessions ();19 public abstract Katze.Array get_saved_sessions ();
20 public abstract Base.Session get_new_session ();20 public abstract Base.Session get_new_session ();
21 public abstract void restore_last_sessions ();21 public abstract void restore_last_sessions ();
22 public abstract void import_session (Katze.Array tabs);22 public abstract void import_session (Katze.Array tabs);
@@ -24,10 +24,15 @@
2424
25 public interface ISession : GLib.Object {25 public interface ISession : GLib.Object {
26 public abstract Katze.Array get_tabs ();26 public abstract Katze.Array get_tabs ();
27 /* Add one tab to the database */
27 public abstract void add_item (Katze.Item item);28 public abstract void add_item (Katze.Item item);
29 /* Attach to a browser */
28 public abstract void attach (Midori.Browser browser);30 public abstract void attach (Midori.Browser browser);
31 /* Attach to a browser and populate it with tabs from the database */
29 public abstract void restore (Midori.Browser browser);32 public abstract void restore (Midori.Browser browser);
33 /* Remove all tabs from the database */
30 public abstract void remove ();34 public abstract void remove ();
35 /* Run when a browser is closed */
31 public abstract void close ();36 public abstract void close ();
32 }37 }
3338
@@ -43,7 +48,7 @@
43 public abstract class Storage : GLib.Object, IStorage {48 public abstract class Storage : GLib.Object, IStorage {
44 public Midori.App app { get; construct; }49 public Midori.App app { get; construct; }
4550
46 public abstract Katze.Array get_sessions ();51 public abstract Katze.Array get_saved_sessions ();
47 public abstract Base.Session get_new_session ();52 public abstract Base.Session get_new_session ();
4853
49 public void start_new_session () {54 public void start_new_session () {
@@ -52,7 +57,7 @@
52 }57 }
5358
54 public void restore_last_sessions () {59 public void restore_last_sessions () {
55 Katze.Array sessions = this.get_sessions ();60 Katze.Array sessions = this.get_saved_sessions ();
56 this.init_sessions (sessions);61 this.init_sessions (sessions);
57 }62 }
5863
@@ -93,7 +98,7 @@
93 public abstract class Session : GLib.Object, ISession {98 public abstract class Session : GLib.Object, ISession {
94 protected GLib.SList<double?> tab_sorting;99 protected GLib.SList<double?> tab_sorting;
95100
96 public Midori.Browser browser { get; protected set; }101 public Midori.Browser? browser { get; protected set; default = null; }
97 public SessionState state { get; protected set; default = SessionState.CLOSED; }102 public SessionState state { get; protected set; default = SessionState.CLOSED; }
98103
99 public abstract void add_item (Katze.Item item);104 public abstract void add_item (Katze.Item item);
@@ -215,12 +220,20 @@
215 }220 }
216221
217 public virtual void close () {222 public virtual void close () {
218 this.browser.add_tab.disconnect (this.tab_added);223 if (this.state == SessionState.CLOSED) {
219 this.browser.add_tab.disconnect (this.helper_data_changed);224 assert (this.browser == null);
220 this.browser.remove_tab.disconnect (this.tab_removed);225 } else {
221 this.browser.switch_tab.disconnect (this.tab_switched);226 this.state = SessionState.CLOSED;
222 this.browser.delete_event.disconnect (this.delete_event);227
223 this.browser.notebook.page_reordered.disconnect (this.tab_reordered);228 this.browser.add_tab.disconnect (this.tab_added);
229 this.browser.add_tab.disconnect (this.helper_data_changed);
230 this.browser.remove_tab.disconnect (this.tab_removed);
231 this.browser.switch_tab.disconnect (this.tab_switched);
232 this.browser.delete_event.disconnect (this.delete_event);
233 this.browser.notebook.page_reordered.disconnect (this.tab_reordered);
234
235 this.browser = null;
236 }
224 }237 }
225238
226#if HAVE_GTK3239#if HAVE_GTK3
@@ -229,7 +242,7 @@
229 protected bool delete_event (Gtk.Widget widget, Gdk.Event event) {242 protected bool delete_event (Gtk.Widget widget, Gdk.Event event) {
230#endif243#endif
231244
232 this.close();245 this.close ();
233 return false;246 return false;
234247
235 }248 }
@@ -481,13 +494,15 @@
481 }494 }
482 }495 }
483496
484 public override void close() {497 public override void close () {
498 /* base.close may unset this.browser, so hold onto it */
499 Midori.Browser? my_browser = this.browser;
485 base.close ();500 base.close ();
486501
487 bool should_break = true;502 bool should_break = true;
488 if (!this.browser.destroy_with_parent) {503 if (my_browser != null && !my_browser.destroy_with_parent) {
489 foreach (Midori.Browser browser in APP.get_browsers ()) {504 foreach (Midori.Browser browser in APP.get_browsers ()) {
490 if (browser != this.browser && !browser.destroy_with_parent) {505 if (browser != my_browser && !browser.destroy_with_parent) {
491 should_break = false;506 should_break = false;
492 break;507 break;
493 }508 }
@@ -595,7 +610,7 @@
595 private class Storage : Base.Storage {610 private class Storage : Base.Storage {
596 private Midori.Database database;611 private Midori.Database database;
597612
598 public override Katze.Array get_sessions () {613 public override Katze.Array get_saved_sessions () {
599 Katze.Array sessions = new Katze.Array (typeof (Session));614 Katze.Array sessions = new Katze.Array (typeof (Session));
600615
601 string sqlcmd = """616 string sqlcmd = """
@@ -717,7 +732,7 @@
717 }732 }
718733
719 private void browser_added (Midori.Browser browser) {734 private void browser_added (Midori.Browser browser) {
720 Base.Session session = browser.get_data<Base.Session> ("tabby-session");735 Base.Session? session = browser.get_data<Base.Session> ("tabby-session");
721 if (session == null) {736 if (session == null) {
722 session = this.storage.get_new_session () as Base.Session;737 session = this.storage.get_new_session () as Base.Session;
723 browser.set_data<Base.Session> ("tabby-session", session);738 browser.set_data<Base.Session> ("tabby-session", session);
@@ -726,7 +741,7 @@
726 }741 }
727742
728 private void browser_removed (Midori.Browser browser) {743 private void browser_removed (Midori.Browser browser) {
729 Base.Session session = browser.get_data<Base.Session> ("tabby-session");744 Base.Session? session = browser.get_data<Base.Session> ("tabby-session");
730 if (session == null) {745 if (session == null) {
731 GLib.warning ("missing session");746 GLib.warning ("missing session");
732 } else {747 } else {
@@ -764,6 +779,17 @@
764 GLib.Idle.add (this.load_session);779 GLib.Idle.add (this.load_session);
765 }780 }
766781
782 private void deactivated () {
783 /* set_open_uris will disconnect itself if called,
784 but it may have been called before we are deactivated */
785 APP.add_browser.disconnect (this.set_open_uris);
786 APP.add_browser.disconnect (this.browser_added);
787 APP.remove_browser.disconnect (this.browser_removed);
788 APP = null;
789
790 this.storage = null;
791 }
792
767 internal Manager () {793 internal Manager () {
768 GLib.Object (name: _("Tabby"),794 GLib.Object (name: _("Tabby"),
769 description: _("Tab and session management."),795 description: _("Tab and session management."),
@@ -771,6 +797,7 @@
771 authors: "André Stösel <andre@stoesel.de>");797 authors: "André Stösel <andre@stoesel.de>");
772798
773 this.activate.connect (this.activated);799 this.activate.connect (this.activated);
800 this.deactivate.connect (this.deactivated);
774 }801 }
775 }802 }
776}803}

Subscribers

People subscribed via source and target branches

to all changes: