Fix potential use of freed pixmap.

This commit is contained in:
Kim Woelders 2014-04-20 07:21:05 +02:00
parent 91514a9427
commit b3d41f5229
9 changed files with 25 additions and 28 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2013 Kim Woelders * Copyright (C) 2004-2014 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -619,7 +619,7 @@ BackgroundRealize(Background * bg, Win win, Drawable draw, unsigned int rw,
#if 0 /* FIXME - Remove? */ #if 0 /* FIXME - Remove? */
if (x == 0 && y == 0) /* Hmmm. Always true. */ if (x == 0 && y == 0) /* Hmmm. Always true. */
{ {
ESetWindowBackgroundPixmap(draw, pmap); ESetWindowBackgroundPixmap(draw, pmap, 1);
} }
else else
{ {
@ -715,7 +715,7 @@ BackgroundApplyWin(Background * bg, Win win)
BackgroundRealize(bg, win, NoXID, w, h, 1, &pmap, &pixel); BackgroundRealize(bg, win, NoXID, w, h, 1, &pmap, &pixel);
if (pmap != NoXID) if (pmap != NoXID)
{ {
ESetWindowBackgroundPixmap(win, pmap); ESetWindowBackgroundPixmap(win, pmap, 0);
EImagePixmapsFree(pmap, NoXID); EImagePixmapsFree(pmap, NoXID);
} }
else else
@ -742,7 +742,7 @@ BackgroundSet(Background * bg, Win win, unsigned int w, unsigned int h)
bg->pmap = pmap; bg->pmap = pmap;
if (pmap != NoXID) if (pmap != NoXID)
ESetWindowBackgroundPixmap(win, pmap); ESetWindowBackgroundPixmap(win, pmap, 1);
else else
ESetWindowBackground(win, pixel); ESetWindowBackground(win, pixel);
EClearWindow(win); EClearWindow(win);

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2013 Kim Woelders * Copyright (C) 2004-2014 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -539,16 +539,16 @@ DeskBackgroundConfigure(Desk * dsk)
if (ECompMgrIsActive()) if (ECompMgrIsActive())
{ {
ECompMgrDeskConfigure(dsk); ECompMgrDeskConfigure(dsk);
ESetWindowBackgroundPixmap(win, NoXID); ESetWindowBackgroundPixmap(win, NoXID, 0);
} }
else else
#endif #endif
{ {
if (pmap != NoXID) if (pmap != NoXID)
{ {
ESetWindowBackgroundPixmap(win, pmap); ESetWindowBackgroundPixmap(win, pmap, 1);
if (dsk->num == 0 && win != VROOT) if (dsk->num == 0 && win != VROOT)
ESetWindowBackgroundPixmap(VROOT, pmap); ESetWindowBackgroundPixmap(VROOT, pmap, 1);
} }
else else
{ {
@ -566,9 +566,9 @@ DeskBackgroundConfigure(Desk * dsk)
if (!Conf.hints.set_xroot_info_on_root_window) if (!Conf.hints.set_xroot_info_on_root_window)
HintsSetRootInfo(EoGetWin(dsk), NoXID, 0); HintsSetRootInfo(EoGetWin(dsk), NoXID, 0);
ESetWindowBackgroundPixmap(win, NoXID); ESetWindowBackgroundPixmap(win, NoXID, 0);
if (dsk->num == 0 && win != VROOT) if (dsk->num == 0 && win != VROOT)
ESetWindowBackgroundPixmap(VROOT, NoXID); ESetWindowBackgroundPixmap(VROOT, NoXID, 0);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2004-2013 Kim Woelders * Copyright (C) 2004-2014 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -476,7 +476,7 @@ EImageApplyToWin(EImage * im, Win win, int flags, int w, int h)
Pixmap pmap, mask; Pixmap pmap, mask;
EImageRenderPixmaps(im, win, flags, &pmap, &mask, w, h); EImageRenderPixmaps(im, win, flags, &pmap, &mask, w, h);
ESetWindowBackgroundPixmap(win, pmap); ESetWindowBackgroundPixmap(win, pmap, 0);
if ((mask != NoXID) || (mask == NoXID && WinIsShaped(win))) if ((mask != NoXID) || (mask == NoXID && WinIsShaped(win)))
EShapeSetMask(win, 0, 0, mask); EShapeSetMask(win, 0, 0, mask);
EImagePixmapsFree(pmap, mask); EImagePixmapsFree(pmap, mask);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2003-2013 Kim Woelders * Copyright (C) 2003-2014 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -483,7 +483,7 @@ EHintsSetDeskInfo(void)
if (Mode.wm.exiting && Mode.root.ext_pmap_valid) if (Mode.wm.exiting && Mode.root.ext_pmap_valid)
{ {
HintsSetRootInfo(VROOT, Mode.root.ext_pmap, 0); HintsSetRootInfo(VROOT, Mode.root.ext_pmap, 0);
ESetWindowBackgroundPixmap(VROOT, Mode.root.ext_pmap); ESetWindowBackgroundPixmap(VROOT, Mode.root.ext_pmap, 1);
} }
} }

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2013 Kim Woelders * Copyright (C) 2004-2014 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -92,7 +92,7 @@ HiwinRenderImageInit(Hiwin * phi)
ewin->mini_pmm.w, ewin->mini_pmm.h, 0); ewin->mini_pmm.w, ewin->mini_pmm.h, 0);
} }
ESetWindowBackgroundPixmap(EoGetWin(phi), NoXID); ESetWindowBackgroundPixmap(EoGetWin(phi), NoXID, 0);
/* Reset shape */ /* Reset shape */
EShapeSetMask(EoGetWin(phi), 0, 0, NoXID); EShapeSetMask(EoGetWin(phi), 0, 0, NoXID);

View File

@ -1167,10 +1167,7 @@ ITApply(Win win, ImageClass * ic, ImageState * is,
/* Set window pixmap */ /* Set window pixmap */
if (pmap == pmm.pmap) if (pmap == pmm.pmap)
{ ESetWindowBackgroundPixmap(win, pmap, 0);
ESetWindowBackgroundPixmap(win, pmap);
EFreeWindowBackgroundPixmap(win);
}
if (pmm.w == w && pmm.h == h) if (pmm.w == w && pmm.h == h)
EShapeSetMask(win, 0, 0, pmm.mask); EShapeSetMask(win, 0, 0, pmm.mask);

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2013 Kim Woelders * Copyright (C) 2004-2014 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -989,7 +989,7 @@ MenuDrawItem(Menu * m, MenuItem * mi, char shape, int state)
} }
} }
ESetWindowBackgroundPixmap(mi->win, mi_pmm->pmap); ESetWindowBackgroundPixmap(mi->win, mi_pmm->pmap, 1);
EShapeSetMask(mi->win, 0, 0, mi_pmm->mask); EShapeSetMask(mi->win, 0, 0, mi_pmm->mask);
EClearWindow(mi->win); EClearWindow(mi->win);

View File

@ -956,14 +956,14 @@ EConfigureWindow(Win win, unsigned int mask, XWindowChanges * wc)
#endif #endif
void void
ESetWindowBackgroundPixmap(Win win, Pixmap pmap) ESetWindowBackgroundPixmap(Win win, Pixmap pmap, int kept)
{ {
if (!win) if (!win)
return; return;
if (win->bgpmap && win->bg_owned) if (win->bgpmap && win->bg_owned)
EFreeWindowBackgroundPixmap(win); EFreeWindowBackgroundPixmap(win);
win->bgpmap = pmap; win->bgpmap = kept ? pmap : NoXID;
win->bg_owned = 0; /* Don't manage pixmap */ win->bg_owned = 0; /* Don't manage pixmap */
win->bgcol = 0xffffffff; /* Hmmm.. */ win->bgcol = 0xffffffff; /* Hmmm.. */
@ -985,7 +985,7 @@ EGetWindowBackgroundPixmap(Win win)
/* Allocate/set new */ /* Allocate/set new */
pmap = ECreatePixmap(win, win->w, win->h, 0); pmap = ECreatePixmap(win, win->w, win->h, 0);
ESetWindowBackgroundPixmap(win, pmap); ESetWindowBackgroundPixmap(win, pmap, 1);
win->bg_owned = 1; /* Manage pixmap */ win->bg_owned = 1; /* Manage pixmap */
return pmap; return pmap;
@ -999,7 +999,7 @@ EFreeWindowBackgroundPixmap(Win win)
if (win->bg_owned) if (win->bg_owned)
EFreePixmap(win->bgpmap); EFreePixmap(win->bgpmap);
win->bgpmap = 0; win->bgpmap = NoXID;
win->bg_owned = 0; win->bg_owned = 0;
} }

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2013 Kim Woelders * Copyright (C) 2004-2014 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -178,7 +178,7 @@ int EGetGeometry(Win win, Window * root_return,
void EGetWindowAttributes(Win win, XWindowAttributes * pxwa); void EGetWindowAttributes(Win win, XWindowAttributes * pxwa);
void EConfigureWindow(Win win, unsigned int mask, void EConfigureWindow(Win win, unsigned int mask,
XWindowChanges * wc); XWindowChanges * wc);
void ESetWindowBackgroundPixmap(Win win, Pixmap pmap); void ESetWindowBackgroundPixmap(Win win, Pixmap pmap, int kept);
Pixmap EGetWindowBackgroundPixmap(Win win); Pixmap EGetWindowBackgroundPixmap(Win win);
void EFreeWindowBackgroundPixmap(Win win); void EFreeWindowBackgroundPixmap(Win win);
void ESetWindowBackground(Win win, unsigned int col); void ESetWindowBackground(Win win, unsigned int col);