One of the warnings CodeSonar® issued in analyzing the open-source gnuchess program was the Leak warning shown in the screenshot fragment below.

Screenshot
fragment: Leak warning in gnuchess

This fragment warns of a potential file pointer resource leak. The file pointer opened on line 297 may be leaked when the function returns on line 304. The problem is that the filepointer is stored in a local variable, rfp. When the function returns on line 304, rfp goes out of scope and the handle to the open file pointer is permanently lost.

The path to the point where the leak occurs is shown in red. Users can inspect the check_magic() call on line 299 by clicking on the plus sign, and see that the path taken through write_magic() does not clean up rfp.