Query module AV Rule 79

name
Resource not released in destructor
description
All resources acquired by a class should be released by its destructor. Avoid the use of the ‘open / close’ pattern, since C++ constructors and destructors provide a safer way to handle resource acquisition and release. Best practice in C++ is to use the ‘RAII’ technique: constructors allocate resources and destructors free them.
kind
problem
problem.severity
warning
precision
high
id
cpp/resource-not-released-in-destructor
tags
efficiency readability external/cwe/cwe-404 external/jsf

Imports

NewDelete

Provides predicates for associating new/malloc calls with delete/free.

cpp

Provides classes and predicates for working with C/C++/ObjC/ObjC++ code.

Predicates

acquireExpr

An expression that acquires a resource, and the kind of resource that is acquired. The kind of a resource indicates which acquisition/release expressions can be paired.

automaticallyReleased
badRelease
exprOrDereference

Gets the expression e or a PointerDereferenceExpr around it.

freedInSameMethod
leakedInSameMethod

Resource r, acquired by acquire, is passed to some external object in the function where it’s acquired. This other object may have taken responsibility for freeing the resource.

qtObject
qtObjectReference
qtParentConstructor
releaseExpr

An expression that releases a resource, and the kind of resource that is released. The kind of a resource indicates which acquisition/release expressions can be paired.

unreleasedResource

Classes