CWE-401: Missing Release of Memory after Effective Lifetime

Export to Word

Description

The product does not sufficiently track and release allocated memory after it has been used, making the memory unavailable for reallocation and reuse.

Extended Description

N/A


ThreatScore

Threat Mapped score: 0.0

Industry: Finiancial

Threat priority: Unclassified


Observed Examples (CVEs)

Related Attack Patterns (CAPEC)

N/A


Attack TTPs

N/A

Modes of Introduction

Phase Note
Implementation Memory leaks have two common and sometimes overlapping causes: Error conditions and other exceptional circumstances often triggered by improper handling of malformed data or unexpectedly interrupted sessions. Confusion over which part of the program is responsible for freeing the memory, since in some languages, developers are responsible for tracking memory allocation and releasing the memory. If there are no more pointers or references to the memory, then it can no longer be tracked and identified for release.

Common Consequences

Potential Mitigations

Applicable Platforms


Demonstrative Examples

Intro: The following C function leaks a block of allocated memory if the call to read() does not return the expected number of bytes:

char* getBlock(int fd) { char* buf = (char*) malloc(BLOCK_SIZE); if (!buf) { return NULL; } if (read(fd, buf, BLOCK_SIZE) != BLOCK_SIZE) { return NULL; } return buf; }

Notes

← Back to CWE list