fix memory leaks
authorDana Jansens <danakj@orodu.net>
Wed, 5 Mar 2008 06:32:52 +0000 (01:32 -0500)
committerDana Jansens <danakj@orodu.net>
Wed, 5 Mar 2008 06:34:40 +0000 (01:34 -0500)
Makefile
dcompmgr.c
display.h
plugin.c
render.c
screen.c
window.c

index 08bf416..3bdb1ba 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ objs = $(sources:.c=.o)
 headers = $(wildcard *.h)
 
 CFLAGS=$(shell pkg-config --cflags xcb-composite xcb-damage glib-2.0) -ggdb -W -Wall
-LIBS=$(shell pkg-config --libs xcb-composite xcb-damage glib-2.0)
+LIBS=$(shell pkg-config --libs xcb-composite xcb-damage glib-2.0) # -lefence
 
 dcompmgr: $(objs)
        $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
index 52774fd..7067a11 100644 (file)
@@ -53,11 +53,13 @@ event(d_display_t *dpy)
         {
             xcb_create_notify_event_t *cev;
             d_screen_t *sc;
+            d_window_t *w;
 
             cev = (xcb_create_notify_event_t*)ev;
             sc = display_screen_from_root(dpy, cev->parent);
             if (!sc) break;
-            screen_add_window(sc, cev->window);
+            w = screen_add_window(sc, cev->window);
+            printf("created 0x%x\n", w);
             break;
         }
         case XCB_DESTROY_NOTIFY:
@@ -71,6 +73,7 @@ event(d_display_t *dpy)
             sc = display_screen_from_root(dpy, dev->event);
             if (!sc) break;
             w = screen_find_window(sc, dev->window);
+            printf("destroyed 0x%x\n", w);
             vis = window_is_mapped(w);
             sc->window_hide(w);
             screen_remove_window(sc, w);
@@ -92,6 +95,7 @@ event(d_display_t *dpy)
             else {
                 sc->window_hide(w);
                 screen_remove_window(sc, w);
+                printf("reparent lost 0x%x\n", w);
             }
             screen_refresh(w->sc);
             break;
@@ -106,6 +110,7 @@ event(d_display_t *dpy)
             sc = display_screen_from_root(dpy, mev->event);
             if (!sc) break;
             w = screen_find_window(sc, mev->window);
+            printf("mapping 0x%x\n", w);
             sc->window_show(w);
             screen_refresh(w->sc);
             break;
@@ -348,6 +353,18 @@ main(int argc, char **argv)
 
     run(dpy);
 
+    {
+        /* make everything hidden */
+        d_list_it_t *sc_it;
+
+        for (sc_it = list_top(dpy->screens); sc_it; sc_it = sc_it->next) {
+            d_screen_t *sc = sc_it->data;
+            d_list_it_t *it;
+            for (it = list_top(sc->stacking); it; it = it->next)
+                sc->window_hide(it->data);
+        }
+    }
+
     cleanup_functions(dpy);
 
     display_unref(dpy);
index 00bb8b1..a1844e7 100644 (file)
--- a/display.h
+++ b/display.h
@@ -2,6 +2,7 @@
 #define dc__display_h
 
 #include <xcb/xcb.h>
+//#include <efence.h>
 
 #include <glib.h>
 
index f3935ad..bb838ad 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -43,6 +43,9 @@ plugin_data_remove(d_list_t *list, int id)
     for (it = list_top(list); it; it = next) {
         d_plugin_data_t *pd = it->data;
         next = it->next;
-        if (pd->id == id) list_delete_link(list, it);
+        if (pd->id == id) {
+            list_delete_link(list, it);
+            plugin_data_free(pd);
+        }
     }
 }
index fbc4070..5510a5c 100644 (file)
--- a/render.c
+++ b/render.c
@@ -23,6 +23,7 @@ typedef struct {
 
 typedef struct {
     xcb_render_picture_t picture;
+    gboolean waiting_picture;
     xcb_void_cookie_t    ck_picture;
 } window_data_t;
 
@@ -96,6 +97,7 @@ render_free(d_screen_t *sc)
     xcb_render_free_picture(sc->dpy->conn, d->overlay_picture);
     xcb_render_free_picture(sc->dpy->conn, d->overlay_buffer);
     free(d);
+    screen_remove_plugin_data(sc, plugin_id);
 }
 
 void
@@ -122,7 +124,7 @@ render_window_show(d_window_t *w)
    
     wd = malloc(sizeof(window_data_t));
     wd->picture = XCB_NONE;
-    wd->ck_picture.sequence = 0;
+    wd->waiting_picture = FALSE;
     window_add_plugin_data(w, plugin_id, wd);
 
     window_ref(w);
@@ -193,7 +195,7 @@ find_visual_format(data_t *d, xcb_visualid_t visual)
 static xcb_render_picture_t
 render_get_picture(d_window_t *w, window_data_t *wd)
 {
-    if (wd->ck_picture.sequence) {
+    if (wd->waiting_picture) {
         xcb_generic_error_t *err;
         //printf("** checking create picture 0x%x\n", w->id);
         err = xcb_request_check(w->sc->dpy->conn, wd->ck_picture);
@@ -202,7 +204,7 @@ render_get_picture(d_window_t *w, window_data_t *wd)
             printf("error creating picture for window 0x%x\n", w->id);
             free(err);
         }
-        wd->ck_picture.sequence = 0;
+        wd->waiting_picture = FALSE;
     }
     //printf("returning picture 0x%x for window 0x%x\n", wd->picture, w->id);
     return wd->picture;
@@ -241,6 +243,7 @@ render_update_picture(d_window_t *w, data_t *d, window_data_t *wd,
                                               wd->picture, px, format,
                                               XCB_RENDER_CP_SUBWINDOW_MODE,
                                               &vals);
+        wd->waiting_picture = TRUE;
     }
 }
 
index 7045104..91195af 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -61,7 +61,11 @@ void
 screen_unref(d_screen_t *sc)
 {
     if (sc && --sc->ref == 0) {
+        d_list_it_t *it;
+
         g_hash_table_unref(sc->winhash);
+        for (it = list_top(sc->stacking); it; it = it->next)
+            window_unref(it->data);
         list_unref(sc->stacking);
         list_unref(sc->plugin_data);
         free(sc);
@@ -114,6 +118,7 @@ screen_register(d_screen_t *sc)
         sck = xcb_get_selection_owner(sc->dpy->conn, arep->atom);
         srep = xcb_get_selection_owner_reply(sc->dpy->conn, sck, NULL);
         taken = srep->owner == w;
+        free(srep);
         if (taken && screen_init(sc)) {
             screen_add_existing_windows(sc);
             ret = TRUE;
@@ -123,6 +128,7 @@ screen_register(d_screen_t *sc)
             ret = FALSE;
         }
     }
+    g_free(arep);
 
     xcb_ungrab_server(sc->dpy->conn);
     xcb_flush(sc->dpy->conn);
index 593c9f4..379bafc 100644 (file)
--- a/window.c
+++ b/window.c
@@ -32,8 +32,11 @@ typedef struct {
 
     xcb_damage_damage_t damage;
 
+    gboolean waiting_attr;
     xcb_get_window_attributes_cookie_t ck_get_attr;
+    gboolean waiting_geom;
     xcb_get_geometry_cookie_t          ck_get_geom;
+    gboolean waiting_pixmap;
     xcb_void_cookie_t                  ck_get_pixmap;
 } d_window_priv_t;
 
@@ -56,9 +59,12 @@ window_new(xcb_window_t id, struct d_screen *sc)
     screen_stacking_add(sc, (d_window_t*)w);
 
     w->ck_get_attr = xcb_get_window_attributes(sc->dpy->conn, id);
+    w->waiting_attr = TRUE;
+
     w->ck_get_geom = xcb_get_geometry(sc->dpy->conn, id);
+    w->waiting_geom = TRUE;
 
-    w->ck_get_pixmap.sequence = 0;
+    w->waiting_pixmap = FALSE;
 
     w->plugin_data = list_new();
 
@@ -100,6 +106,8 @@ window_update_pixmap(d_window_priv_t *w)
 {
     xcb_pixmap_t p;
 
+    if (window_is_zombie((d_window_t*)w)) return;
+
     /* XXX can we save it for until we get the new pixmap? */
     if ((p = window_get_pixmap((d_window_t*)w))) {
         xcb_free_pixmap(w->sc->dpy->conn, p);
@@ -112,6 +120,7 @@ window_update_pixmap(d_window_priv_t *w)
     w->ck_get_pixmap = 
         xcb_composite_name_window_pixmap_checked(w->sc->dpy->conn,
                                                  w->id, w->pixmap);
+    w->waiting_pixmap = TRUE;
     xcb_flush(w->sc->dpy->conn);
 }
 
@@ -161,7 +170,7 @@ gboolean
 window_is_input_only(d_window_t *pubw)
 {
     d_window_priv_t *w = (d_window_priv_t*)pubw;
-    if (w->ck_get_attr.sequence)
+    if (w->waiting_attr)
         window_get_attributes_reply(w);
     return w->input_only;
 }
@@ -171,7 +180,7 @@ window_get_area(d_window_t *pubw, int *x, int *y, int *width, int *height,
                 int *border_width)
 {
     d_window_priv_t *w = (d_window_priv_t*)pubw;
-    if (w->ck_get_geom.sequence)
+    if (w->waiting_geom)
         window_get_geometry_reply(w);
     *x = w->x;
     *y = w->y;
@@ -205,7 +214,7 @@ window_get_attributes_reply(d_window_priv_t *w)
         printf("error getting attributes for window 0x%x\n", w->id);
         free(err);
     }
-    w->ck_get_attr.sequence = 0;
+    w->waiting_attr = 0;
 }
 
 static void
@@ -235,14 +244,14 @@ window_get_geometry_reply(d_window_priv_t *w)
         printf("error getting geometry for window 0x%x\n", w->id);
         free(err);
     }
-    w->ck_get_geom.sequence = 0;
+    w->waiting_geom = 0;
 }
 
 gboolean
 window_is_mapped(d_window_t *pubw)
 {
     d_window_priv_t *w = (d_window_priv_t*)pubw;
-    if (w->ck_get_attr.sequence)
+    if (w->waiting_attr)
         window_get_attributes_reply(w);
     return w->mapped;
 }
@@ -252,7 +261,7 @@ window_get_pixmap(d_window_t *pubw)
 {
     d_window_priv_t *w = (d_window_priv_t*)pubw;
 
-    if (w->ck_get_pixmap.sequence) {
+    if (w->waiting_pixmap) {
         xcb_generic_error_t *err;
         //printf("** checking get pixmap 0x%x\n", w->id);
         err = xcb_request_check(w->sc->dpy->conn, w->ck_get_pixmap);
@@ -261,7 +270,7 @@ window_get_pixmap(d_window_t *pubw)
             printf("error getting named pixmap for window 0x%x\n", w->id);
             free(err);
         }
-        w->ck_get_pixmap.sequence = 0;
+        w->waiting_pixmap = FALSE;
     }
     //printf("returning pixmap 0x%x for window 0x%x\n", w->pixmap, w->id);
     return w->pixmap;
@@ -271,7 +280,7 @@ xcb_visualid_t
 window_get_visual(d_window_t *pubw)
 {
     d_window_priv_t *w = (d_window_priv_t*)pubw;
-    if (w->ck_get_attr.sequence)
+    if (w->waiting_attr)
         window_get_attributes_reply(w);
     return w->visual;
 }
@@ -283,8 +292,8 @@ window_configure(d_window_t *pubw, int x, int y, int width, int height,
     d_window_priv_t *w = (d_window_priv_t*)pubw;
 
     /* this overrides any reply from our get_geometry call */
-    if (w->ck_get_geom.sequence)
-        w->ck_get_geom.sequence = 0;
+    if (w->waiting_geom)
+        w->waiting_geom = FALSE;
     w->x = x;
     w->y = y;
     w->w = width;