summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2009-09-23 10:53:51 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2009-09-30 10:04:28 +1000
commit2d4bab18c0d894619f044f29769c67c2f63b540a (patch)
treecdc9678f9f8c9f1ca4a10e396c0d508ece82d8fc
parent290a9639db3e420ec4caf0e6aee9f7386724c765 (diff)
render: Plug a memory leak in AddGlyph. (#23286)
AddGlyph was missing the FreePicture() call that DeleteGlyph used, resulting in a memory leak when more than one Glyph was added in a RenderAddGlyphs request. Since the code in AddGlyph and DeleteGlyph is identical, move into a static function to avoid such mistakes in the future. X.Org Bug 23286 <http://bugs.freedesktop.org/show_bug.cgi?id=23286> (cherry picked from commit f772014c435f56db56520ca13ffa39431684f122)
-rw-r--r--render/glyph.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/render/glyph.c b/render/glyph.c
index 7c044aada..6327c9fda 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -272,13 +272,31 @@ CheckDuplicates (GlyphHashPtr hash, char *where)
#define DuplicateRef(a,b)
#endif
+static void
+FreeGlyphPicture(GlyphPtr glyph)
+{
+ PictureScreenPtr ps;
+ int i;
+
+ for (i = 0; i < screenInfo.numScreens; i++)
+ {
+ ScreenPtr pScreen = screenInfo.screens[i];
+
+ FreePicture ((pointer) GlyphPicture (glyph)[i], 0);
+
+ ps = GetPictureScreenIfSet (pScreen);
+ if (ps)
+ (*ps->UnrealizeGlyph) (pScreen, glyph);
+ }
+}
+
+
void
FreeGlyph (GlyphPtr glyph, int format)
{
CheckDuplicates (&globalGlyphs[format], "FreeGlyph");
if (--glyph->refcnt == 0)
{
- PictureScreenPtr ps;
GlyphRefPtr gr;
int i;
int first;
@@ -305,17 +323,7 @@ FreeGlyph (GlyphPtr glyph, int format)
globalGlyphs[format].tableEntries--;
}
- for (i = 0; i < screenInfo.numScreens; i++)
- {
- ScreenPtr pScreen = screenInfo.screens[i];
-
- FreePicture ((pointer) GlyphPicture (glyph)[i], 0);
-
- ps = GetPictureScreenIfSet (pScreen);
- if (ps)
- (*ps->UnrealizeGlyph) (pScreen, glyph);
- }
-
+ FreeGlyphPicture(glyph);
FreeGlyphPrivates(glyph);
xfree (glyph);
}
@@ -334,15 +342,7 @@ AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id)
TRUE, glyph->sha1);
if (gr->glyph && gr->glyph != DeletedGlyph && gr->glyph != glyph)
{
- PictureScreenPtr ps;
- int i;
-
- for (i = 0; i < screenInfo.numScreens; i++)
- {
- ps = GetPictureScreenIfSet (screenInfo.screens[i]);
- if (ps)
- (*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
- }
+ FreeGlyphPicture(glyph);
FreeGlyphPrivates(glyph);
xfree (glyph);
glyph = gr->glyph;