]> Pileus Git - wmpus/commitdiff
Run through valgrind (fix memory leaks)
authorAndy Spencer <andy753421@gmail.com>
Wed, 5 Oct 2011 03:23:32 +0000 (03:23 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 5 Oct 2011 03:23:32 +0000 (03:23 +0000)
sys-x11.c
util.c
util.h
wm-wmii.c

index a5ae667f6e3e794676df052921ad6c54a03a8988..072216b76ca54c45550ae37be72c719e1d6a5aee 100644 (file)
--- a/sys-x11.c
+++ b/sys-x11.c
@@ -275,7 +275,7 @@ static void process_event(int type, XEvent *ev, win_t *root)
        //printf("event: %d\n", type);
 
        /* Common data for all these events ... */
-       ptr_t ptr; mod_t mod;
+       ptr_t ptr = {}; mod_t mod = {};
        if (type == KeyPress    || type == KeyRelease    ||
            type == ButtonPress || type == ButtonRelease ||
            type == MotionNotify) {
diff --git a/util.c b/util.c
index cb196bffb6e6bb78674e78f76f03aa5b72d023df..aeb766eaa01f32d65234e84261b97d63d503efe3 100644 (file)
--- a/util.c
+++ b/util.c
@@ -55,12 +55,14 @@ list_t *list_append(list_t *head, void *data)
        return last ? head : node;
 }
 
-list_t *list_remove(list_t *head, list_t *node)
+list_t *list_remove(list_t *head, list_t *node, int freedata)
 {
        list_t *next = node->next;
        list_t *prev = node->prev;
        if (next) next->prev = prev;
        if (prev) prev->next = next;
+       if (freedata)
+               free(node->data);
        free(node);
        return head == node ? next : head;
 }
diff --git a/util.h b/util.h
index 6400cd9ccb6c2d13c724288b8a50a026b326cebc..697ca9ce04a2b387abe0f55dd90b9e2bbba2172e 100644 (file)
--- a/util.h
+++ b/util.h
@@ -47,7 +47,7 @@ void list_insert_after(list_t *after, void *data);
 
 list_t *list_append(list_t *before, void *data);
 
-list_t *list_remove(list_t *head, list_t *item);
+list_t *list_remove(list_t *head, list_t *item, int freedata);
 
 int list_length(list_t *item);
 
index a4c05b75ef993303d4f523a30971086c643b5165..06b71f67694830210204c2a374b23dd23c8d6f03 100644 (file)
--- a/wm-wmii.c
+++ b/wm-wmii.c
@@ -299,21 +299,22 @@ static layer_t cut_win(win_t *win, tag_t *tag)
        list_t *ldpy, *lcol, *lrow, *lflt;
        layer_t layer = searchl(tag, win, &ldpy, &lcol, &lrow, &lflt);
 
-       dpy_t  *dpy   = DPY(ldpy);
        if (layer == tiling) {
-               col_t  *col  = COL(lcol);
+               dpy_t *dpy = DPY(ldpy);
+               col_t *col = COL(lcol);
                col->row  = lrow->prev ? lrow->prev->data :
                            lrow->next ? lrow->next->data : NULL;
-               col->rows = list_remove(col->rows, lrow);
+               col->rows = list_remove(col->rows, lrow, 1);
                if (col->rows == NULL && (lcol->next || lcol->prev)) {
                        dpy->col  = lcol->prev ? lcol->prev->data :
                                    lcol->next ? lcol->next->data : NULL;
-                       dpy->cols = list_remove(dpy->cols, lcol);
+                       dpy->cols = list_remove(dpy->cols, lcol, 1);
                }
        }
 
        if (layer == floating) {
-               dpy->flts = list_remove(dpy->flts, lflt);
+               dpy_t *dpy = DPY(ldpy);
+               dpy->flts = list_remove(dpy->flts, lflt, 1);
                dpy->flt  = dpy->flts ? list_last(dpy->flts)->data : NULL;
                if (!dpy->flt && dpy->col && dpy->col->row)
                        dpy->layer = tiling;
@@ -513,7 +514,7 @@ static void raise_float(win_t *win)
                        break;
        if (cur) {
                flt_t *flt = cur->data;
-               wm_dpy->flts = list_remove(wm_dpy->flts, cur);
+               wm_dpy->flts = list_remove(wm_dpy->flts, cur, 0);
                wm_dpy->flts = list_append(wm_dpy->flts, flt);
                sys_raise(win);
        }
@@ -587,9 +588,18 @@ static void tag_set(win_t *win, int name)
 static void tag_switch(int name)
 {
        printf("tag_switch: %d\n", name);
-       if ((wm_col == NULL || wm_row == NULL) && wm_flt == NULL)
-               wm->tags = list_remove(wm->tags,
-                               list_find(wm->tags, wm_tag));
+       tag_t *old = wm_tag;
+       if ((wm_col == NULL || wm_row == NULL) && wm_flt == NULL) {
+               list_t *ltag = list_find(wm->tags, old);
+               wm->tags = list_remove(wm->tags, ltag, 1);
+               while (old->dpys) {
+                       dpy_t *dpy = old->dpys->data;
+                       while (dpy->cols)
+                               dpy->cols = list_remove(dpy->cols, dpy->cols, 1);
+                       old->dpys = list_remove(old->dpys, old->dpys, 1);
+               }
+               free(old);
+       }
        wm_tag = tag_find(name);
 }
 
@@ -865,10 +875,12 @@ void wm_remove(win_t *win)
        print_txt();
        for (list_t *tag = wm->tags; tag; tag = tag->next)
                cut_win(win, tag->data);
+       free(win->wm);
        set_focus(wm_focus);
        wm_update();
        print_txt();
 }
+
 void wm_init(win_t *root)
 {
        printf("wm_init: %p\n", root);