fix some memory problems
authorDana Jansens <danakj@orodu.net>
Wed, 5 Mar 2008 07:15:43 +0000 (02:15 -0500)
committerDana Jansens <danakj@orodu.net>
Wed, 5 Mar 2008 07:16:02 +0000 (02:16 -0500)
Makefile
dcompmgr.c
display.c
display.h
efence.h [new file with mode: 0644]
list.c
plugin.c
render.c
screen.c
window.c

index 3bdb1ba..d3d8202 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ sources = $(wildcard *.c)
 objs = $(sources:.c=.o)
 headers = $(wildcard *.h)
 
 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) # -lefence
+CFLAGS=$(shell pkg-config --cflags xcb-composite xcb-damage glib-2.0) -ggdb -W -Wall #-DEFENCE
+LIBS=$(shell pkg-config --libs xcb-composite xcb-damage glib-2.0) #-lefence
 
 dcompmgr: $(objs)
        $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
 
 dcompmgr: $(objs)
        $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
index 7067a11..29ec004 100644 (file)
@@ -1,3 +1,5 @@
+#include "efence.h"
+
 #include "screen.h"
 #include "window.h"
 #include "list.h"
 #include "screen.h"
 #include "window.h"
 #include "list.h"
@@ -59,7 +61,6 @@ event(d_display_t *dpy)
             sc = display_screen_from_root(dpy, cev->parent);
             if (!sc) break;
             w = screen_add_window(sc, cev->window);
             sc = display_screen_from_root(dpy, cev->parent);
             if (!sc) break;
             w = screen_add_window(sc, cev->window);
-            printf("created 0x%x\n", w);
             break;
         }
         case XCB_DESTROY_NOTIFY:
             break;
         }
         case XCB_DESTROY_NOTIFY:
@@ -73,7 +74,6 @@ event(d_display_t *dpy)
             sc = display_screen_from_root(dpy, dev->event);
             if (!sc) break;
             w = screen_find_window(sc, dev->window);
             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);
             vis = window_is_mapped(w);
             sc->window_hide(w);
             screen_remove_window(sc, w);
@@ -95,7 +95,6 @@ event(d_display_t *dpy)
             else {
                 sc->window_hide(w);
                 screen_remove_window(sc, w);
             else {
                 sc->window_hide(w);
                 screen_remove_window(sc, w);
-                printf("reparent lost 0x%x\n", w);
             }
             screen_refresh(w->sc);
             break;
             }
             screen_refresh(w->sc);
             break;
@@ -110,7 +109,6 @@ event(d_display_t *dpy)
             sc = display_screen_from_root(dpy, mev->event);
             if (!sc) break;
             w = screen_find_window(sc, mev->window);
             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;
             sc->window_show(w);
             screen_refresh(w->sc);
             break;
@@ -345,7 +343,7 @@ main(int argc, char **argv)
         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 (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)
+            for (it = list_bottom(sc->stacking); it; it = it->prev)
                 if (window_is_mapped(it->data))
                     sc->window_show(it->data);
         }
                 if (window_is_mapped(it->data))
                     sc->window_show(it->data);
         }
@@ -360,8 +358,10 @@ main(int argc, char **argv)
         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 (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);
+            for (it = list_top(sc->stacking); it; it = it->next) {
+                if (window_is_mapped(it->data))
+                    sc->window_hide(it->data);
+            }
         }
     }
 
         }
     }
 
index 1beee21..1ce9e13 100644 (file)
--- a/display.c
+++ b/display.c
@@ -1,3 +1,5 @@
+#include "efence.h"
+
 #include "display.h"
 #include "screen.h"
 #include "list.h"
 #include "display.h"
 #include "screen.h"
 #include "list.h"
@@ -195,11 +197,11 @@ display_unref(d_display_t *dpy)
     if (dpy && --dpy->ref == 0) {
         d_list_it_t *it;
 
     if (dpy && --dpy->ref == 0) {
         d_list_it_t *it;
 
-        xcb_disconnect(dpy->conn);
-
         for (it = list_top(dpy->screens); it; it = it->next)
             screen_unref(it->data);
         list_unref(dpy->screens);
         for (it = list_top(dpy->screens); it; it = it->next)
             screen_unref(it->data);
         list_unref(dpy->screens);
+
+        xcb_disconnect(dpy->conn);
         free(dpy);
     }
 }
         free(dpy);
     }
 }
index a1844e7..00bb8b1 100644 (file)
--- a/display.h
+++ b/display.h
@@ -2,7 +2,6 @@
 #define dc__display_h
 
 #include <xcb/xcb.h>
 #define dc__display_h
 
 #include <xcb/xcb.h>
-//#include <efence.h>
 
 #include <glib.h>
 
 
 #include <glib.h>
 
diff --git a/efence.h b/efence.h
new file mode 100644 (file)
index 0000000..d1c4f97
--- /dev/null
+++ b/efence.h
@@ -0,0 +1,5 @@
+#ifdef EFENCE
+#include <stdlib.h>
+#include <string.h>
+#include <efence.h>
+#endif
diff --git a/list.c b/list.c
index 49a9f78..2339b06 100644 (file)
--- a/list.c
+++ b/list.c
@@ -1,3 +1,5 @@
+#include "efence.h"
+
 #include "list.h"
 #include <assert.h>
 #include <stdlib.h>
 #include "list.h"
 #include <assert.h>
 #include <stdlib.h>
index bb838ad..4d32126 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -1,3 +1,5 @@
+#include "efence.h"
+
 #include "plugin.h"
 #include "list.h"
 #include <stdlib.h>
 #include "plugin.h"
 #include "list.h"
 #include <stdlib.h>
index 5510a5c..8d272fb 100644 (file)
--- a/render.c
+++ b/render.c
@@ -1,3 +1,5 @@
+#include "efence.h"
+
 #include "render.h"
 #include "screen.h"
 #include "window.h"
 #include "render.h"
 #include "screen.h"
 #include "window.h"
index 91195af..b16373a 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -1,3 +1,5 @@
+#include "efence.h"
+
 #include "screen.h"
 #include "display.h"
 #include "plugin.h"
 #include "screen.h"
 #include "display.h"
 #include "plugin.h"
@@ -61,11 +63,13 @@ void
 screen_unref(d_screen_t *sc)
 {
     if (sc && --sc->ref == 0) {
 screen_unref(d_screen_t *sc)
 {
     if (sc && --sc->ref == 0) {
-        d_list_it_t *it;
+        d_list_it_t *it, *next;
 
         g_hash_table_unref(sc->winhash);
 
         g_hash_table_unref(sc->winhash);
-        for (it = list_top(sc->stacking); it; it = it->next)
+        for (it = list_top(sc->stacking); it; it = next) {
+            next = it->next;
             window_unref(it->data);
             window_unref(it->data);
+        }
         list_unref(sc->stacking);
         list_unref(sc->plugin_data);
         free(sc);
         list_unref(sc->stacking);
         list_unref(sc->plugin_data);
         free(sc);
@@ -350,7 +354,8 @@ screen_remove_plugin_data(d_screen_t *sc, int id)
     plugin_data_remove(sc->plugin_data, id);
 }
 
     plugin_data_remove(sc->plugin_data, id);
 }
 
-void screen_refresh(d_screen_t *sc)
+void
+screen_refresh(d_screen_t *sc)
 {
     sc->need_repaint = TRUE;
     //printf("*** need repaint! ***\n");
 {
     sc->need_repaint = TRUE;
     //printf("*** need repaint! ***\n");
index 379bafc..f4a97a9 100644 (file)
--- a/window.c
+++ b/window.c
@@ -1,3 +1,5 @@
+#include "efence.h"
+
 #include "window.h"
 #include "screen.h"
 #include "plugin.h"
 #include "window.h"
 #include "screen.h"
 #include "plugin.h"
@@ -342,6 +344,7 @@ window_create_damage(d_window_t *pubw)
     if (!window_is_input_only(pubw)) {
         assert(w->damage == XCB_NONE);
         w->damage = xcb_generate_id(w->sc->dpy->conn);
     if (!window_is_input_only(pubw)) {
         assert(w->damage == XCB_NONE);
         w->damage = xcb_generate_id(w->sc->dpy->conn);
+        //printf("creating damage 0x%x\n", w->damage);
         xcb_damage_create(w->sc->dpy->conn, w->damage, w->id,
                           XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY);
     }
         xcb_damage_create(w->sc->dpy->conn, w->damage, w->id,
                           XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY);
     }
@@ -352,6 +355,7 @@ void window_destroy_damage(d_window_t *pubw)
     d_window_priv_t *w = (d_window_priv_t*)pubw;
 
     if (w->damage) {
     d_window_priv_t *w = (d_window_priv_t*)pubw;
 
     if (w->damage) {
+        //printf("destroying damage 0x%x\n", w->damage);
         xcb_damage_destroy(w->sc->dpy->conn, w->damage);
         w->damage = XCB_NONE;
     }
         xcb_damage_destroy(w->sc->dpy->conn, w->damage);
         w->damage = XCB_NONE;
     }