changeset 889:13cdd6999598 trunk

[svn] - aosd: fixed ugly memleak in ghosd sources
author giacomo
date Wed, 21 Mar 2007 11:19:49 -0700
parents 7e24265fe540
children 6050c7583b06
files ChangeLog src/aosd/ghosd-internal.h src/aosd/ghosd.c
diffstat 3 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 21 07:36:32 2007 -0700
+++ b/ChangeLog	Wed Mar 21 11:19:49 2007 -0700
@@ -1,3 +1,10 @@
+2007-03-21 14:36:32 +0000  Giacomo Lozito <james@develia.org>
+  revision [1876]
+  alsa: small changes
+  trunk/src/alsa/audio.c |    3 ++-
+  1 file changed, 2 insertions(+), 1 deletion(-)
+
+
 2007-03-21 14:24:33 +0000  Giacomo Lozito <james@develia.org>
   revision [1874]
   aosd: use g_locale_to_utf8 for osd strings (needs testing)
--- a/src/aosd/ghosd-internal.h	Wed Mar 21 07:36:32 2007 -0700
+++ b/src/aosd/ghosd-internal.h	Wed Mar 21 11:19:49 2007 -0700
@@ -20,13 +20,18 @@
   void *data;
 } EventButtonCallback;
 
+typedef struct {
+  Pixmap pixmap;
+  int set;
+} GhosdBackground;
+
 struct _Ghosd {
   Display *dpy;
   Window win;
   int transparent;
   int x, y, width, height;
-  
-  Pixmap background;
+
+  GhosdBackground background;
   RenderCallback render;
   EventButtonCallback eventbutton;
 };
--- a/src/aosd/ghosd.c	Wed Mar 21 07:36:32 2007 -0700
+++ b/src/aosd/ghosd.c	Wed Mar 21 11:19:49 2007 -0700
@@ -72,7 +72,7 @@
 
   gc = XCreateGC(ghosd->dpy, pixmap, 0, NULL);
   if (ghosd->transparent) {
-    XCopyArea(ghosd->dpy, ghosd->background, pixmap, gc,
+    XCopyArea(ghosd->dpy, ghosd->background.pixmap, pixmap, gc,
               0, 0, ghosd->width, ghosd->height, 0, 0);
   } else {
     XFillRectangle(ghosd->dpy, pixmap, gc,
@@ -98,6 +98,7 @@
     cairo_t *cr = cairo_create(surf);
     ghosd->render.func(ghosd, cr, ghosd->render.data);
     cairo_destroy(cr);
+    cairo_surface_destroy(surf);
   }
 
   /* point window at its new backing pixmap. */
@@ -192,9 +193,13 @@
 void
 ghosd_show(Ghosd *ghosd) {
   if (ghosd->transparent) {
-    if (ghosd->background)
-      XFreePixmap(ghosd->dpy, ghosd->background);
-    ghosd->background = take_snapshot(ghosd);
+    if (ghosd->background.set)
+    {
+      XFreePixmap(ghosd->dpy, ghosd->background.pixmap);
+      ghosd->background.set = 0;
+    }
+    ghosd->background.pixmap = take_snapshot(ghosd);
+    ghosd->background.set = 1;
   }
 
   ghosd_render(ghosd);
@@ -282,14 +287,18 @@
   ghosd->win = win;
   ghosd->transparent = 1;
   ghosd->eventbutton.func = NULL;
+  ghosd->background.set = 0;
 
   return ghosd;
 }
 
 void
 ghosd_destroy(Ghosd* ghosd) {
-  if (ghosd->background)
-    XFreePixmap(ghosd->dpy, ghosd->background);
+  if (ghosd->background.set)
+  {
+    XFreePixmap(ghosd->dpy, ghosd->background.pixmap);
+    ghosd->background.set = 0;
+  }
   XDestroyWindow(ghosd->dpy, ghosd->win);
 }