diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-05-26 22:58:14 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-05-26 22:58:14 -0700 |
commit | bc51dd4cdf617ba44ed1231d411eb8d63616e371 (patch) | |
tree | b5de86614cc27588dee639108ec12154e08f6e31 /xfontsel.c | |
parent | 4faa8afa1856a015a63efb12a466b5fd060c1af5 (diff) |
Prevent memory leak in GetFontNames if no fonts are matched
Defer creating ParseRec until after we check for numFonts = 0 and return.
Fixes error found by Parfait 0.5.0.2 bug checking tool:
Memory leak of pointer '<unknown>' allocated with XtMalloc(40)
at line 466 of app/xfontsel/xfontsel.c in function 'GetFontNames'.
pointer allocated at line 447 with XtMalloc(40).
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xfontsel.c')
-rw-r--r-- | xfontsel.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -444,14 +444,13 @@ struct ParseRec { void GetFontNames(XtPointer closure) { Display *dpy = (Display*)closure; - ParseRec *parseRec = XtNew(ParseRec); + ParseRec *parseRec; int f, field, count; String *fontNames; Boolean *b; int work_priority = 0; - fontNames = parseRec->fontNames = - XListFonts(dpy, AppRes.pattern, 32767, &numFonts); + fontNames = XListFonts(dpy, AppRes.pattern, 32767, &numFonts); fonts = (FontValues*)XtMalloc( numFonts*sizeof(FontValues) ); fontInSet = (Boolean*)XtMalloc( numFonts*sizeof(Boolean) ); @@ -466,6 +465,8 @@ void GetFontNames(XtPointer closure) return; } numBadFonts = 0; + parseRec = XtNew(ParseRec); + parseRec->fontNames = fontNames; parseRec->fonts = fonts; parseRec->num_fonts = count = matchingFontCount = numFonts; parseRec->fieldValues = fieldValues; |