JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C#


CSHARP.ALLOC.LEAK.NOTSTORED : Closeable Not Stored (C#)

Summary

A closeable has not been immediately stored into a local variable.

The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. However, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources (such as database, streams, open files, etc.). For these reasons, they should be disposed, or otherwise the system might run into an out of resource exception. The dispose operation should always be performed, in every execution path. For this reason, the using or finally constructs should be used.

This checker verifies that resources are always released after being open, for every execution path. This checker recognizes and accepts as correct code where a resource is stored into a field or returned from a method and is then closed at the end, at least for some frequent scenarios.

Properties

Class Name Closeable Not Stored (C#)
Significance reliability
Mnemonic CSHARP.ALLOC.LEAK.NOTSTORED
Categories
CWE CWE:400 Uncontrolled Resource Consumption
Availability Available for C# only.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Closeable Not Stored (C#)"

Resolution

Guarantee that all resources are released, typically by using a using or a finally construct. In general, avoid storing resources into fields or returning resources from methods or letting a method close a resource passed to it as a parameter.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.