description | title | ms.date | ms.topic | f1_keywords | helpviewer_keywords | ms.assetid | ||
---|---|---|---|---|---|---|---|---|
Learn more about: C26403 RESET_OR_DELETE_OWNER |
C26403 |
07/21/2017 |
conceptual |
|
|
7e14868d-df86-4df3-98d3-71b1e80ba14e |
Owner pointers are like unique pointers: they own a resource exclusively, and manage release of the resource, as well as its transfers to other owners. This check validates that a local owner pointer properly maintains its resource through all execution paths in a function. If the resource was not transferred to another owner, or was not explicitly release, the checker warns, and points to the declaration of the pointer variable.
For more information, see the C++ Core Guidelines.
-
Currently this check doesn’t give the exact path which fails to release the resource. This behavior may be improved in future releases. It may be difficult to find exact location for a fix. The better approach is to try to replace plain pointers in complex functions with unique pointers to avoid any risks.
-
The check may discard an over-complicated function in order to not block code analysis. Generally, the complexity of functions should be maintained under some reasonable threshold. We may consider adding a local complexity check to the C++ Core Guidelines module if there is clear demand for it. This limitation is applicable to other rules which are sensitive to data flow.
-
The warning may fire on clearly false positive cases where memory is deleted only after the nullness check of a pointer. This is the result of a current limitation of the tool’s API, but it may be improved in future.
gsl::owner<int*> sequence = GetRandomSequence(); // C26403
try
{
StartSimulation(sequence);
}
catch (const std::exception& e)
{
if (KnownException(e))
return; // Skipping the path which deletes the owner.
ReportException(e);
}
delete [] sequence;