fix for ghost memory leaks
authorCampbell Barton <ideasman42@gmail.com>
Wed, 5 Aug 2009 02:40:51 +0000 (02:40 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 5 Aug 2009 02:40:51 +0000 (02:40 +0000)
- ghost data wasn't being freed (added wm_ghost_exit() call to wm_init_exit.c)
- GHOST_EventManager wasn't freeing GHOST_IEventConsumer's
- ghost/X11 wasnt calling XCloseDisplay(), some junk from X11 wasnt being freed
- ghost/X11 XAllocNamedColor wasn't freeing the colors when done making a custom cursor.

intern/ghost/intern/GHOST_EventManager.cpp
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h
intern/ghost/intern/GHOST_WindowManager.cpp
intern/ghost/intern/GHOST_WindowX11.cpp
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_window.c
source/blender/windowmanager/wm_window.h

index f9b1311..92cea8d 100644 (file)
@@ -51,6 +51,15 @@ GHOST_EventManager::GHOST_EventManager()
 GHOST_EventManager::~GHOST_EventManager()
 {
        disposeEvents();
+
+       TConsumerVector::iterator iter= m_consumers.begin();
+       while (iter != m_consumers.end())
+       {
+               GHOST_IEventConsumer* consumer = *iter;
+               delete consumer;
+               m_consumers.erase(iter);
+               iter = m_consumers.begin();
+       }
 }
 
 
index dbdb65a..5dba76a 100644 (file)
@@ -148,6 +148,13 @@ GHOST_SystemX11(
        
 }
 
+GHOST_SystemX11::
+~GHOST_SystemX11()
+{
+       XCloseDisplay(m_display);
+}
+
+
        GHOST_TSuccess 
 GHOST_SystemX11::
 init(
index afd960d..782f08f 100644 (file)
@@ -59,6 +59,12 @@ public:
        GHOST_SystemX11(
        );
        
+       /**
+        * Destructor.
+        */
+       virtual ~GHOST_SystemX11();
+
+
                GHOST_TSuccess 
        init(
        );
index 2b08099..af96653 100644 (file)
@@ -54,6 +54,7 @@ GHOST_WindowManager::GHOST_WindowManager() :
 
 GHOST_WindowManager::~GHOST_WindowManager()
 {
+       /* m_windows is freed by GHOST_System::disposeWindow */
 }
 
 
index 41c62be..f9774b6 100644 (file)
@@ -1325,13 +1325,12 @@ setWindowCustomCursorShape(
        int fg_color, 
        int bg_color
 ){
+       Colormap colormap= DefaultColormap(m_display, DefaultScreen(m_display));
        Pixmap bitmap_pix, mask_pix;
        XColor fg, bg;
        
-       if(XAllocNamedColor(m_display, DefaultColormap(m_display, DefaultScreen(m_display)),
-               "White", &fg, &fg) == 0) return GHOST_kFailure;
-       if(XAllocNamedColor(m_display, DefaultColormap(m_display, DefaultScreen(m_display)),
-               "Black", &bg, &bg) == 0) return GHOST_kFailure;
+       if(XAllocNamedColor(m_display, colormap, "White", &fg, &fg) == 0) return GHOST_kFailure;
+       if(XAllocNamedColor(m_display, colormap, "Black", &bg, &bg) == 0) return GHOST_kFailure;
 
        if (m_custom_cursor) {
                XFreeCursor(m_display, m_custom_cursor);
@@ -1347,6 +1346,9 @@ setWindowCustomCursorShape(
        XFreePixmap(m_display, bitmap_pix);
        XFreePixmap(m_display, mask_pix);
 
+    XFreeColors(m_display, colormap, &fg.pixel, 1, 0L);
+    XFreeColors(m_display, colormap, &bg.pixel, 1, 0L);
+
        return GHOST_kSuccess;
 }
 
index 599844f..7179efb 100644 (file)
@@ -274,6 +274,8 @@ void WM_exit(bContext *C)
 
        RNA_exit();
        
+       wm_ghost_exit();
+
        CTX_free(C);
        
        if(MEM_get_memory_blocks_in_use()!=0) {
index 31e6de2..4d80836 100644 (file)
@@ -756,6 +756,14 @@ void wm_ghost_init(bContext *C)
        }       
 }
 
+void wm_ghost_exit(void)
+{
+       if(g_system)
+               GHOST_DisposeSystem(g_system);
+
+       g_system= NULL;
+}
+
 /* **************** timer ********************** */
 
 /* to (de)activate running timers temporary */
index c2a2b00..f159f7f 100644 (file)
@@ -33,6 +33,7 @@ struct bScreen;
 
 /* *************** internal api ************** */
 void           wm_ghost_init                   (bContext *C);
+void           wm_ghost_exit(void);
 
 wmWindow       *wm_window_new                  (bContext *C);
 void           wm_window_free                  (bContext *C, wmWindow *win);