[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: KDE/kdebase/workspace/plasma/applets/systemtray/protocols/fdo
From:       Casper Clemence <maninalift () googlemail ! com>
Date:       2009-05-28 14:46:32
Message-ID: 4c1964560905280746n57b6131bxfc53c32bf8f777ba () mail ! gmail ! com
[Download RAW message or body]

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@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@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@kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
> 
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic