[cppcheck] resource leak xf86Configure.c

Martin Ettl ettl.martin at gmx.de
Sat Oct 3 04:56:29 PDT 2009


Hi friends,

here is another issue (spotted out by cppcheck, a static code analysis tool).

It prints the following warning:

../xfree86/common/xf86Configure.c,266,possible error,Resource leak: fd

Take a look into file xf86Configure.c at line 266:

...
	fd = open("/dev/wsmouse", 0);
	if (fd > 0) {
	    DFLT_MOUSE_DEV = "/dev/wsmouse";
	    DFLT_MOUSE_PROTO = "wsmouse";
	    close(fd);
	} else {
	    ErrorF("cannot open /dev/wsmouse\n");
	}
...

As you can see, the if()-statement is wrong because open returns the filepointer or, in case of an error -1 !! See the attached patch that corrects that issue.

Best regards

Martin



-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_resource_leak.patch
Type: text/x-patch
Size: 432 bytes
Desc: not available
Url : http://lists.x.org/archives/xorg-devel/attachments/20091003/8143c937/attachment.bin 


More information about the xorg-devel mailing list