[PATCH xdbedizzy] Resouce cleanup fixes

Jeff Smith whydoubt at yahoo.com
Sat Mar 20 12:44:30 PDT 2010


Running xdbedizzy through valgrind (with no arguments to xdbedizzy) and
no 'matching double buffer capable visual' produced
  "definitely lost: 800 bytes in 2 blocks."
  "still reachable: 41,240 bytes in 30 blocks."
This patch reduces this to
  "definitely lost: 0 bytes in 0 blocks."
  "still reachable: 35 bytes in 2 blocks."

Signed-off-by: Jeff Smith <whydoubt at yahoo.com>
---
 xdbedizzy.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/xdbedizzy.c b/xdbedizzy.c
index aadcf82..09c9ee4 100644
--- a/xdbedizzy.c
+++ b/xdbedizzy.c
@@ -124,6 +124,7 @@ unsigned long getColor(Colormap cmap, const char *color_name)
     status = XAllocNamedColor(dpy, cmap, color_name, &color, &exact);
     if (status == 0) {
         fprintf(stderr, "%s: Couldn't get color: %s\n", ProgramName, color_name);
+        XCloseDisplay(dpy);
         exit(EXIT_FAILURE);
     }
     return (color.pixel);
@@ -263,8 +264,11 @@ choose_DB_visual( /* Input */         Display *dpy, Bool listVis, int visclass,
                 }
             }
         }
+        XFree(XvisInfo);
     }
 
+    XdbeFreeVisualInfo(DBEvisInfo);
+
     if (chosenVisual) {
         if (listVis) {
             printf("\n");
@@ -528,11 +532,13 @@ int main(int argc, char *argv[])
 
         if (!XdbeQueryExtension (dpy, &dbeMajorVersion, &dbeMinorVersion)) {
             fprintf(stderr, "%s: XdbeQueryExtension() failed.\n", ProgramName);
+            XCloseDisplay(dpy);
             exit(EXIT_FAILURE);
         }
 
         if ((visual = choose_DB_visual(dpy, listVis, visclass, &depth)) == NULL) {
             fprintf(stderr, "%s: Failed to find matching double buffer capable visual.\n", ProgramName);
+            XCloseDisplay(dpy);
             exit(EXIT_FAILURE);
         }
         fprintf(stdout, "%s: Chose visual ID: %#4x depth: %d\n\n",
@@ -559,6 +565,7 @@ int main(int argc, char *argv[])
                         CWBorderPixel | CWColormap | CWBackPixel, &attrs);
     if (win == None) {
         fprintf(stderr, "%s: Couldn't window.\n", ProgramName);
+        XCloseDisplay(dpy);
         exit(EXIT_FAILURE);
     }
 
@@ -572,6 +579,8 @@ int main(int argc, char *argv[])
         buf = XdbeAllocateBackBufferName (dpy, win, swapInfo.swap_action);
         if (buf == None) {
             fprintf(stderr, "%s: Couldn't create buffers\n", ProgramName);
+            XDestroyWindow(dpy, win);
+            XCloseDisplay(dpy);
             exit(EXIT_FAILURE);
         }
         else {
@@ -600,6 +609,14 @@ int main(int argc, char *argv[])
 
     main_loop();
 
+    XUnmapWindow(dpy, win);
+
+    XFreeGC(dpy, gc_black);
+    XFreeGC(dpy, gc_pink);
+    XFreeGC(dpy, gc_green);
+    XFreeGC(dpy, gc_orange);
+    XFreeGC(dpy, gc_blue);
+
     XDestroyWindow(dpy, win);
     XCloseDisplay(dpy);
     
-- 
1.6.0.6

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the xorg-devel mailing list