[PATCH:libXfont] Fix memory leak in allocation failure path of BitmapOpenScalable()

Alan Coopersmith alan.coopersmith at oracle.com
Mon May 16 18:33:26 PDT 2011


Go ahead and fill in the font->info pointers so that bitmapUnloadScalable()
will free the bits that were allocated, even if some were not.

Error: Memory leak (CWE 401)
   Memory leak of pointer <unknown> allocated with ComputeScaledProperties(...)
        at line 1629 of /export/alanc/X.Org/git/lib/libXfont/src/bitmap/bitscale.c in function 'BitmapOpenScalable'.
          pointer allocated at line 1616 with ComputeScaledProperties(...).
          <unknown> leaks when props != 0 at line 1623.

[ This bug was found by the Parfait 0.3.7 bug checking tool.
  For more information see http://labs.oracle.com/projects/parfait/ ]

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/bitmap/bitscale.c |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/bitmap/bitscale.c b/src/bitmap/bitscale.c
index cf16bff..50818c6 100644
--- a/src/bitmap/bitscale.c
+++ b/src/bitmap/bitscale.c
@@ -1620,19 +1620,16 @@ BitmapOpenScalable (FontPathElementPtr fpe,
     if (!sourceFont->refcnt)
 	FontFileCloseFont((FontPathElementPtr) 0, sourceFont);
 
+    font->info.props = props;
+    font->info.nprops = propCount;
+    font->info.isStringProp = isStringProp;
+
     if (propCount && (!props || !isStringProp))
     {
-	font->info.nprops = 0;
-	font->info.props = (FontPropPtr)0;
-	font->info.isStringProp = (char *)0;
 	bitmapUnloadScalable(font);
 	return AllocError;
     }
 
-    font->info.props = props;
-    font->info.nprops = propCount;
-    font->info.isStringProp = isStringProp;
-
     *pFont = font;
     return Successful;
 }
-- 
1.7.3.2



More information about the xorg-devel mailing list