[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-xorg-devel
Subject:    [PATCH:app/bitmap 1/2] Stop memory leaks from XtNewString(StripFilename(filename))
From:       Alan Coopersmith <alan.coopersmith () oracle ! com>
Date:       2014-12-30 2:39:09
Message-ID: 1419907150-4508-1-git-send-email-alan.coopersmith () oracle ! com
[Download RAW message or body]

StripFilename() already allocates a new string for its result,
we don't need to duplicate it and then lose the pointer to the
first one.

Fixes errors found by Oracle Parfait 1.5.1 bug checking tool:

Error: Memory leak (CWE 401)
   Memory leak of pointer pointer allocated with StripFilename(filename)
        at line 1119 of Bitmap.c in function 'BWReadFile'.
          pointer allocated at line 1106 with StripFilename(filename).
          pointer leaks when StripFilename(filename) != NULL at line 1106.
Error: Memory leak (CWE 401)
   Memory leak of pointer pointer allocated with StripFilename(filename)
        at line 1119 of Bitmap.c in function 'BWReadFile'.
          pointer allocated at line 1106 with StripFilename(filename).

Error: Memory leak (CWE 401)
   Memory leak of pointer pointer allocated with StripFilename(filename)
        at line 1222 of Bitmap.c in function 'BWWriteFile'.
          pointer allocated at line 1202 with StripFilename(filename).
          pointer leaks when StripFilename(filename) != NULL at line 1202.
Error: Memory leak (CWE 401)
   Memory leak of pointer pointer allocated with StripFilename(filename)
        at line 1222 of Bitmap.c in function 'BWWriteFile'.
          pointer allocated at line 1202 with StripFilename(filename).

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
---
 Bitmap.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Bitmap.c b/Bitmap.c
index 76464f9..2a8e46d 100644
--- a/Bitmap.c
+++ b/Bitmap.c
@@ -1103,7 +1103,7 @@ BWReadFile(Widget w, _Xconst _XtString filename, _Xconst _XtString basename) /*
 	XtFree(BW->bitmap.filename);
 	BW->bitmap.filename = XtNewString(filename);
 	XtFree(BW->bitmap.basename);
-	BW->bitmap.basename= XtNewString(StripFilename(filename));
+	BW->bitmap.basename = StripFilename(filename);
 
 	BWUnmark(w);
 
@@ -1199,7 +1199,7 @@ BWWriteFile(Widget w, _Xconst _XtString filename, _Xconst _XtString basename)
 	XtFree(BW->bitmap.filename);
 	BW->bitmap.filename = XtNewString(filename);
 	XtFree(BW->bitmap.basename);
-	BW->bitmap.basename= XtNewString(StripFilename(filename));
+	BW->bitmap.basename = StripFilename(filename);
     }
     if (!basename) basename = BW->bitmap.basename;
     else {
-- 
1.7.9.2

_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic