[AD] X11 memory leak fixes

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


This patch contains a few fixes to memory leaks on X11. Unfortunately,
this doesn't solve all leaks since most libraries and drivers of X11
seem to be leaky themselves as well. Even if we call the correct clean
up functions, some sleaks still remain, so they seem to be
unfortunately out of our reach.

Kind Regards, B.
From 3fbcd8744b25c1b505f3ef2af85f56c306ab358e Mon Sep 17 00:00:00 2001
From: Beoran <beoran@xxxxxxxxx>
Date: Mon, 1 Jul 2013 17:10:46 +0200
Subject: [PATCH 1/2] Try to solve some memory leaks on X11. Buggy X11 drivers
 and libraries still leak themselves though...

---
 src/x/xdisplay.c |   23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/x/xdisplay.c b/src/x/xdisplay.c
index 4f59723..97d0b4c 100644
--- a/src/x/xdisplay.c
+++ b/src/x/xdisplay.c
@@ -584,6 +584,14 @@ static void xdpy_destroy_display_hook_default(ALLEGRO_DISPLAY *d, bool is_last)
       glx->xvinfo = NULL;
    }
 
+   if ((glx->glxwindow) && (glx->glxwindow != glx->window)) {
+     glXDestroyWindow(s->x11display, glx->glxwindow);
+     glx->glxwindow = NULL;
+     ALLEGRO_DEBUG("destroy glx window");
+   }
+   
+    // glXDestroyWindow(s->x11display, glx->glxwindow);
+
    _al_cond_destroy(&glx->mapped);
 
    ALLEGRO_DEBUG("destroy window.\n");
@@ -1035,7 +1043,7 @@ static void xdpy_set_window_title_default(ALLEGRO_DISPLAY *display, const char *
    {
       Atom WM_NAME = XInternAtom(system->x11display, "WM_NAME", False);
       Atom _NET_WM_NAME = XInternAtom(system->x11display, "_NET_WM_NAME", False);
-      char *list[] = {(void *)title};
+      char *list[1] = { (char *) title }; 
       XTextProperty property;
 
       Xutf8TextListToTextProperty(system->x11display, list, 1, XUTF8StringStyle,
@@ -1045,10 +1053,15 @@ static void xdpy_set_window_title_default(ALLEGRO_DISPLAY *display, const char *
       XFree(property.value);
    }
    {
-      XClassHint hint;
-      hint.res_name = strdup(title); // Leak? (below too...)
-      hint.res_class = strdup(title);
-      XSetClassHint(system->x11display, glx->window, &hint);
+      XClassHint * hint;
+      hint = XAllocClassHint();
+      if (hint) { 
+         /* There's no need to use strdup here at all.  And doing so would cause a memory leak. */
+         hint->res_name = (char *) title; 
+         hint->res_class = (char *) title;        
+         XSetClassHint(system->x11display, glx->window, hint);
+         XFree(hint);
+      } 
    }
    _al_mutex_unlock(&system->lock);
 }
-- 
1.7.10.4


From 7d14d7a6592572c8dbc46eac244eb812cb653488 Mon Sep 17 00:00:00 2001
From: Beoran <beoran@xxxxxxxxx>
Date: Mon, 1 Jul 2013 17:22:18 +0200
Subject: [PATCH 2/2] Tiny correction in destroying GLX window on X11.

---
 src/x/xdisplay.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/x/xdisplay.c b/src/x/xdisplay.c
index 97d0b4c..6c4a73a 100644
--- a/src/x/xdisplay.c
+++ b/src/x/xdisplay.c
@@ -586,12 +586,10 @@ static void xdpy_destroy_display_hook_default(ALLEGRO_DISPLAY *d, bool is_last)
 
    if ((glx->glxwindow) && (glx->glxwindow != glx->window)) {
      glXDestroyWindow(s->x11display, glx->glxwindow);
-     glx->glxwindow = NULL;
+     glx->glxwindow = 0;
      ALLEGRO_DEBUG("destroy glx window");
    }
    
-    // glXDestroyWindow(s->x11display, glx->glxwindow);
-
    _al_cond_destroy(&glx->mapped);
 
    ALLEGRO_DEBUG("destroy window.\n");
-- 
1.7.10.4



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/