[PATCH:app/bitmap 1/2] Stop memory leaks from XtNewString(StripFilename(filename))
Alan Coopersmith
alan.coopersmith at oracle.com
Mon Dec 29 18:39:09 PST 2014
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 at 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
More information about the xorg-devel
mailing list