Collapsing the tree frees the list items, so we cannot take a reference
into that list before calling collapse.  This could be the source of the
crash reported to the mailing list.  This changes the code so we get a
pointer to the session before collapsing the tree.

Additionally I've found two memory leaks in related code:
* old_list contains all items, so use that for cleanup, otherwise
  some items could leak

* list_copy was never freed
---
 window-choose.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/window-choose.c b/window-choose.c
index 678e661..86980a4 100644
--- a/window-choose.c
+++ b/window-choose.c
@@ -181,8 +181,8 @@ window_choose_free(struct window_pane *wp)
        struct window_choose_mode_item  *item;
        u_int                            i;
 
-       for (i = 0; i < ARRAY_LENGTH(&data->list); i++) {
-               item = &ARRAY_ITEM(&data->list, i);
+       for (i = 0; i < ARRAY_LENGTH(&data->old_list); i++) {
+               item = &ARRAY_ITEM(&data->old_list, i);
                if (data->freefn != NULL && item->wcd != NULL)
                        data->freefn(item->wcd);
                free(item->name);
@@ -289,6 +289,7 @@ window_choose_collapse(struct window_pane *wp, struct 
session *s)
        if (!ARRAY_EMPTY(&list_copy)) {
                ARRAY_FREE(&data->list);
                ARRAY_CONCAT(&data->list, &list_copy);
+               ARRAY_FREE(&list_copy);
        }
 }
 
@@ -296,11 +297,11 @@ void
 window_choose_collapse_all(struct window_pane *wp)
 {
        struct window_choose_mode_data  *data = wp->modedata;
-       struct window_choose_mode_item  *item, *chosen;
-       struct session                  *s;
+       struct window_choose_mode_item  *item;
+       struct session                  *s, *chosen;
        u_int                            i;
 
-       chosen = &ARRAY_ITEM(&data->list, data->selected);
+       chosen = ARRAY_ITEM(&data->list, data->selected).wcd->session;
 
        RB_FOREACH(s, sessions, &sessions)
                window_choose_collapse(wp, s);
@@ -309,7 +310,7 @@ window_choose_collapse_all(struct window_pane *wp)
        for (i = 0; i < ARRAY_LENGTH(&data->list); i++) {
                item = &ARRAY_ITEM(&data->list, i);
 
-               if (chosen->wcd->session != item->wcd->tree_session)
+               if (chosen != item->wcd->tree_session)
                        continue;
 
                if (item->wcd->type & TREE_SESSION)
-- 
1.7.9.7


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to