KDE/kdebase/workspace/plasma/applets/systemtray/protocols/fdo

Casper Clemence maninalift at googlemail.com
Thu May 28 16:46:32 CEST 2009


hmmm... there must be a design pattern that achieves this elegantly
with no extra overhead... maybe

If there are certain actions that need to be performed at whatever the
function was exited. If only it were possible to define (private)
classes locally that had access to local variables as if they were
global.

void foo()
{

   // display, picture bg are declared

   private class Janitor{
      ~Janitor()
      {
         XRenderFreePicture(display, picture);
         XFreePixmap(display, bg);
      }
   }

   Janitor  sweeper_upper; //now we don't need to worry about anything
when we return


  // the body of the function

}

...or else to define a "destructor" for a function.

hmmm... or you could use a #define whenever you have functions that
manage their own resources

function foo(){
   #define return_foo  ....

   // body of function using return_foo for all return statements

   #undef return_foo
}

not quite so nice?

2009/5/22 Alexis Ménard <menard at kde.org>:
> SVN commit 971259 by menard:
>
> Mr X really really love when we free his pixmap memory.
>
> Hop hop hop, never forget to release the data that you allocate when
> you return in the middle of a method. This code was leaking like a
> hell. I'll close the bug open for that.
>
> CCBUG:183191
> CCMAIL:plasma-devel at kde.org
>
>  M  +8 -3      x11embedcontainer.cpp
>
>
> --- trunk/KDE/kdebase/workspace/plasma/applets/systemtray/protocols/fdo/x11embedcontainer.cpp #971258:971259
> @@ -244,9 +244,11 @@
>     else
>       image = background.copy().toImage(); //With the X11 graphics engine, we have to create a copy first, else we get a crash
>
> -    if(d->oldBackgroundImage == image)
> +    if(d->oldBackgroundImage == image) {
> +      XFreePixmap(display, bg);
> +      XRenderFreePicture(display, picture);
>       return;
> -
> +    }
>     d->oldBackgroundImage = image;
>
>     if (background.paintEngine()->type() != QPaintEngine::X11) {
> @@ -342,8 +344,11 @@
>             ximage.blue_mask    = 0x001f;
>         }
>         ximage.obdata           = 0;
> -        if (XInitImage(&ximage) == 0)
> +        if (XInitImage(&ximage) == 0) {
> +            XRenderFreePicture(display, picture);
> +            XFreePixmap(display, bg);
>             return;
> +        }
>
>         Pixmap pm = XCreatePixmap(display, clientWinId(), width(), height(), ximage.depth);
>         GC gc = XCreateGC(display, pm, 0, 0);
> _______________________________________________
> Plasma-devel mailing list
> Plasma-devel at kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>


More information about the Plasma-devel mailing list