Operation on a Resource after Expiration or Release |
Weakness ID: 672 (Weakness Base) | Status: Draft |
Description Summary
Example 1
In the following C/C++ example the method processMessage is used to process a message received in the input array of char arrays. The input message array contains two char arrays the first is the length of the message and the second is the body of the message. The length of the message is retrieved and used to allocate enough memory for a local char array, messageBody, to be created for the message body. The messageBody is processed in the method processMessageBody that will return an error if an error occurs while processing. If an error occurs then the return result variable is set to indicate an error and the messageBody char array memory is released using the method free and an error message is sent to the logError method.
However, the call to the method logError includes the messageBody after the memory for messageBody has been released using the free method. This can cause unexpected results and may lead to system crashes. A variable should never be used after its memory resources have been released.
Nature | Type | ID | Name | View(s) this relationship pertains to |
---|---|---|---|---|
ChildOf | Category | 361 | Time and State | Development Concepts (primary)699 |
ChildOf | Weakness Base | 666 | Operation on Resource in Wrong Phase of Lifetime | Research Concepts (primary)1000 |
ChildOf | Category | 808 | 2010 Top 25 - Weaknesses On the Cusp | Weaknesses in the 2010 CWE/SANS Top 25 Most Dangerous Programming Errors (primary)800 |
ParentOf | Weakness Base | 298 | Improper Validation of Certificate Expiration | Research Concepts (primary)1000 |
ParentOf | Weakness Base | 324 | Use of a Key Past its Expiration Date | Research Concepts (primary)1000 |
ParentOf | Weakness Base | 416 | Use After Free | Research Concepts (primary)1000 |
ParentOf | Weakness Base | 562 | Return of Stack Variable Address | Research Concepts (primary)1000 |
ParentOf | Weakness Base | 613 | Insufficient Session Expiration | Research Concepts (primary)1000 |