MISRA C:2023 Dir 4.13
Functions which are designed to provide operations on a resource should be called in an appropriate sequence
Since R2024a
Description
This checker is deactivated in a default Polyspace® as You Code analysis. See Checkers Deactivated in Polyspace as You Code Analysis (Polyspace Access).
Directive Definition
Functions which are designed to provide operations on a resource should be called in an appropriate sequence.
Rationale
You typically use functions operating on a resource in the following way:
You allocate the resource.
For example, you open a file or critical section.
You use the resource.
For example, you read from the file or perform operations in the critical section.
You deallocate the resource.
For example, you close the file or critical section.
For your functions to operate as you expect, perform the steps in sequence. For instance, if you call a resource allocation function on a certain execution path, you must call a deallocation function on that path.
Polyspace Implementation
Polyspace Bug Finder™ detects a violation of this rule if you specify multitasking options and your code contains one of these defects:
Missing lock
: A task calls an unlock function before calling the corresponding lock function.Missing unlock
: A task calls a lock function but ends without a call to the corresponding unlock function.Double lock
: A task calls a lock function twice without an intermediate call to an unlock function.Double unlock
: A task calls an unlock function twice without an intermediate call to a lock function.
For more information on the multitasking options, see Multitasking.
Extend Checker
You might be using multithreading functions that are not supported by Polyspace. Extend this checker by mapping the functions of your multithreading functions to their known POSIX® equivalent. See Extend Concurrency Defect Checkers to Unsupported Multithreading Environments.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Code design |
Category: Advisory |
AGC Category: Advisory |
Version History
Introduced in R2024a