On Sat, 03 Nov 2012, Carlos R. Mafra escribió:

> On Sat,  3 Nov 2012 at 19:53:54 +0100, Rodolfo García Peñas (kix) wrote:
> > From: "Rodolfo García Peñas (kix)" <[email protected]>
> > 
> > The new function unset_icon_image() removes the RImage and the
> > file path for a given icon.
> > ---
> >  src/icon.c |   21 ++++++++++++---------
> >  1 file changed, 12 insertions(+), 9 deletions(-)
> > 
> > diff --git a/src/icon.c b/src/icon.c
> > index 018333b..fce0a51 100644
> > --- a/src/icon.c
> > +++ b/src/icon.c
> > @@ -66,6 +66,7 @@ static void get_pixmap_icon_from_user_icon(WIcon *icon);
> >  static void get_pixmap_icon_from_default_icon(WIcon *icon);
> >  
> >  static void icon_update_pixmap(WIcon *icon, RImage *image);
> > +static void unset_icon_image(WIcon *icon);
> >  
> >  static RImage *get_default_image(WScreen *scr);
> >  /****** Notification Observers ******/
> > @@ -251,11 +252,7 @@ void wIconDestroy(WIcon * icon)
> >     if (icon->pixmap)
> >             XFreePixmap(dpy, icon->pixmap);
> >  
> > -   if (icon->file)
> > -           wfree(icon->file);
> > -
> > -   if (icon->file_image != NULL)
> > -           RReleaseImage(icon->file_image);
> > +   unset_icon_image(icon);
> >  
> >     wCoreDestroy(icon->core);
> >     wfree(icon);
> > @@ -390,10 +387,7 @@ Bool wIconChangeImageFile(WIcon *icon, char *file)
> >     /* New image! */
> >     if (!error && image) {
> >             /* Remove the old one */
> > -           if (icon->file_image) {
> > -                   RReleaseImage(icon->file_image);
> > -                   icon->file_image = NULL;
> > -           }
> > +           unset_icon_image(icon);
> 
> By using unset_icon_image() here you are doing more than
> the original code (ie wfree(icon->file)) and also less (by not
> setting icon->file_image to NULL).
> 
> I haven't looked at the details, but it's not obvious why you
> can change that at this point.
 
Yes, you are right, is new code. The WIcon struct has two pointers:

WIcon->file_image contains the rimage (an image) for the icon.
WIcon->file contains the file path for a image.

The normal case is that WIcon->file contains the file path for 
WIcon->file_image. If we free only the file_image but don't free file, then we 
are using two (different) images in the icon. 

The function wIconChangeImageFile sets both values:

        if (ok_flag && image) {
                /* Remove the old one */
                unset_icon_image(icon);

                /* Set the new image */
                icon->file_image = image;
                icon->file = wstrdup(path);

In the original the icon->file was not freeded, therefore the memory was lost.

Cheers,
kix
 
> >             /* Set the new image */
> >             icon->file_image = image;
> > @@ -585,6 +579,15 @@ void wIconSelect(WIcon * icon)
> >     }
> >  }
> >  
> > +static void unset_icon_image(WIcon *icon)
> > +{
> > +   if (icon->file)
> > +           wfree(icon->file);
> > +
> > +   if (icon->file_image)
> > +           RReleaseImage(icon->file_image);
> > +}
> > +
> 
> 
> -- 
> To unsubscribe, send mail to [email protected].

-- 
||// //\\// Rodolfo "kix" Garcia
||\\// //\\ http://www.kix.es/


-- 
To unsubscribe, send mail to [email protected].

Reply via email to