[PATCH:libXext] XeviGetVisualInfo: Free & clear *evi_return, not evi_return pointer

Alan Coopersmith alan.coopersmith at oracle.com
Sat Mar 8 20:17:20 PST 2014


evi_return is passed in as a pointer to a location into which
XeviGetVisualInfo is expected to write a pointer to the memory
it allocated for the returned structures.  If we're failing and
bailing out, we need to dispose of the pointer we set, not the
one passed into us (which the caller may have put on the stack
or allocated as part of a larger structure).

Flagged by cppcheck 1.64:
[lib/libXext/src/XEVI.c:182] -> [lib/libXext/src/XEVI.c:186]:
 (warning) Possible null pointer dereference: evi_return - otherwise it
           is redundant to check it against null.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/XEVI.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/XEVI.c b/src/XEVI.c
index 6d77fdf..c9b172c 100644
--- a/src/XEVI.c
+++ b/src/XEVI.c
@@ -183,8 +183,10 @@ Status XeviGetVisualInfo(
 	_XEatDataWords(dpy, rep.length);
 	UnlockDisplay(dpy);
 	SyncHandle();
-	if (evi_return)
-	   Xfree(evi_return);
+	if (*evi_return) {
+	   Xfree(*evi_return);
+	   *evi_return = NULL;
+	}
 	if (temp_xInfo)
 	   Xfree(temp_xInfo);
 	if (temp_conflict)
-- 
1.7.9.2



More information about the xorg-devel mailing list