From dacae58710f7033d5295c50cf6262783350e938d Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 29 Dec 2014 18:28:00 -0800 Subject: Stop memory leak in XmuWriteBitmapDataToFile() StripFilename() allocates a new string for its result, so after we're done with it, free it instead of just losing the pointer to it. Fixes errors found by Oracle Parfait 1.5.1 bug checking tool: Error: Memory leak (CWE 401) Memory leak of pointer basename allocated with StripFilename(filename) at line 712 of Bitmap.c in function 'XmuWriteBitmapDataToFile'. basename allocated at line 691 with StripFilename(filename). basename leaks when i >= data_length at line 702. Error: Memory leak (CWE 401) Memory leak of pointer basename allocated with StripFilename(filename) at line 715 of Bitmap.c in function 'XmuWriteBitmapDataToFile'. basename allocated at line 691 with StripFilename(filename). Signed-off-by: Alan Coopersmith --- Bitmap.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Bitmap.c b/Bitmap.c index 2a8e46d..8fbead9 100644 --- a/Bitmap.c +++ b/Bitmap.c @@ -687,10 +687,14 @@ XmuWriteBitmapDataToFile(_Xconst _XtString filename, else file = fopen(filename, "w+"); - if (!basename || !strcmp(basename, "") || !strcmp(basename, "-")) - basename = StripFilename(filename); - if (file) { + String new_basename; + + if (!basename || !strcmp(basename, "") || !strcmp(basename, "-")) + basename = new_basename = StripFilename(filename); + else + new_basename = NULL; + fprintf(file, "#define %s_width %d\n", basename, width); fprintf(file, "#define %s_height %d\n", basename, height); if (QuerySet(x_hot, y_hot)) { @@ -709,6 +713,7 @@ XmuWriteBitmapDataToFile(_Xconst _XtString filename, if (file != stdout) fclose(file); + XtFree(new_basename); return BitmapSuccess; } -- cgit v1.2.3