Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

As noted in undefined behavior 179 of Annex J of the C standard Standard [ISO/IEC 9899:2011], the behavior of a program is undefined when

...

Freeing memory that is not allocated dynamically can lead to serious errors similar to those discussed in MEM31-C. Free dynamically allocated memory exactly once. The specific consequences of this error depend on the implementation, but they range from nothing to abnormal program termination. Regardless of the implementation, avoid calling free() on anything other than a pointer returned by a dynamic - memory allocation function, such as malloc(), calloc(), realloc(), or aligned_alloc.

...

Tool

Version

Checker

Description

LDRA tool suite

Include Page
LDRA_VLDRA_V

Compass/ROSE

  

Can detect some violations of this rule

483 S

Fully implemented

.

Coverity

Include Page
Coverity_V
Coverity_V

BAD_FREE

Identifies calls to free() where the argument is a pointer to a function or an array. It also detects the cases where Free is used on an address-of expression, which can never be heap allocated. Coverity Prevent cannot discover all violations of this rule, so further verification is necessary.

Klocwork

Include Page
Klocwork_V
Klocwork_V

FNH.MIGHT
FNH.MUST
FUM.GEN.MIGHT
FUM.GEN.MUST

 

LDRA tool suite

Include Page
LDRA_V
LDRA_V

483 S

Fully implemented

Compass/ROSE

  Can detect some violations of this rule.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

...

...

TS 17961 (Draft)Reallocating or freeing memory that was not dynamically allocatied [xfree]
MITRE CWE

...

...

Free of invalid pointer not on the heap

...

Bibliography

[Seacord 2005] Chapter 4, "Dynamic Memory Management"

...