| Impact | Details |
|---|---|
|
DoS: Crash, Exit, or Restart; DoS: Instability; DoS: Resource Consumption (CPU); DoS: Resource Consumption (Memory) |
Scope: Availability
Most memory leaks result in general product reliability problems, but if an attacker can intentionally trigger a memory leak, the attacker might be able to launch a denial of service attack (by crashing or hanging the program) or take advantage of other unexpected program behavior resulting from a low memory condition.
|
|
Reduce Performance |
Scope: Other |
| Phase(s) | Mitigation |
|---|---|
|
Implementation |
Strategy: Libraries or Frameworks Choose a language or tool that provides automatic memory management, or makes manual memory management less error-prone. For example, glibc in Linux provides protection against free of invalid pointers. When using Xcode to target OS X or iOS, enable automatic reference counting (ARC) [REF-391]. To help correctly and consistently manage memory when programming in C++, consider using a smart pointer class such as std::auto_ptr (defined by ISO/IEC ISO/IEC 14882:2003), std::shared_ptr and std::unique_ptr (specified by an upcoming revision of the C++ standard, informally referred to as C++ 1x), or equivalent solutions such as Boost. |
|
Architecture and Design |
Use an abstraction library to abstract away risky APIs. Not a complete solution.
|
|
Architecture and Design; Build and Compilation |
The Boehm-Demers-Weiser Garbage Collector or valgrind can be used to detect leaks in code.
Note:
This is not a complete solution as it is not 100% effective.
|
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 772 | Missing Release of Resource after Effective Lifetime |
| CanFollow | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 390 | Detection of Error Condition Without Action |
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 404 | Improper Resource Shutdown or Release |
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 404 | Improper Resource Shutdown or Release |
| Phase | Note |
|---|---|
| Implementation |
Memory leaks have two common and sometimes overlapping causes:
|
C (Undetermined Prevalence)
C++ (Undetermined Prevalence)
Example 1
The following C function leaks a block of allocated memory if the call to read() does not return the expected number of bytes:
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
| Reference | Description |
|---|---|
|
Memory leak because function does not free() an element of a data structure.
|
|
|
Memory leak when counter variable is not decremented.
|
|
|
chain: reference count is not decremented, leading to memory leak in OS by sending ICMP packets.
|
|
|
Kernel uses wrong function to release a data structure, preventing data from being properly tracked by other code.
|
|
|
Memory leak via unknown manipulations as part of protocol test suite.
|
|
|
Memory leak via a series of the same command.
|
| Ordinality | Description |
|---|---|
|
Resultant
|
(where the weakness is typically related to the presence of some other weaknesses)
|
| Method | Details |
|---|---|
|
Fuzzing |
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
Effectiveness: High |
|
Automated Static Analysis |
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Effectiveness: High |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 398 | 7PK - Code Quality |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 730 | OWASP Top Ten 2004 Category A9 - Denial of Service |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 861 | The CERT Oracle Secure Coding Standard for Java (2011) Chapter 18 - Miscellaneous (MSC) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1152 | SEI CERT Oracle Secure Coding Standard for Java - Guidelines 49. Miscellaneous (MSC) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1162 | SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1238 | SFP Primary Cluster: Failure to Release Memory |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1399 | Comprehensive Categorization: Memory Safety |
Rationale
This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.Comments
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.Relationship
Terminology
| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| PLOVER | Memory leak | ||
| 7 Pernicious Kingdoms | Memory Leak | ||
| CLASP | Failure to deallocate data | ||
| OWASP Top Ten 2004 | A9 | CWE More Specific | Denial of Service |
| CERT C Secure Coding | MEM31-C | Exact | Free dynamically allocated memory when no longer needed |
| The CERT Oracle Secure Coding Standard for Java (2011) | MSC04-J | Do not leak memory | |
| Software Fault Patterns | SFP14 | Failure to Release Resource | |
| OMG ASCPEM | ASCPEM-PRF-14 |
| Submissions | |||
|---|---|---|---|
| Submission Date | Submitter | Organization | |
|
2006年07月19日
(CWE Draft 3, 2006年07月19日) |
PLOVER | ||
| Modifications | |||
| Modification Date | Modifier | Organization | |
|
2025年04月03日
(CWE 4.17, 2025年04月03日) |
CWE Content Team | MITRE | |
| updated Description, Diagram, Modes_of_Introduction | |||
| 2023年06月29日 | CWE Content Team | MITRE | |
| updated Mapping_Notes | |||
| 2023年04月27日 | CWE Content Team | MITRE | |
| updated Detection_Factors, References, Relationships, Time_of_Introduction | |||
| 2023年01月31日 | CWE Content Team | MITRE | |
| updated Common_Consequences, Description | |||
| 2022年10月13日 | CWE Content Team | MITRE | |
| updated Taxonomy_Mappings | |||
| 2021年03月15日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020年08月20日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020年02月24日 | CWE Content Team | MITRE | |
| updated References, Relationships, Taxonomy_Mappings | |||
| 2019年06月20日 | CWE Content Team | MITRE | |
| updated Description, Name | |||
| 2019年01月03日 | CWE Content Team | MITRE | |
| updated Common_Consequences, Demonstrative_Examples, Name, References, Relationships, Taxonomy_Mappings, Type, Weakness_Ordinalities | |||
| 2017年11月08日 | CWE Content Team | MITRE | |
| updated References, Relationships, Taxonomy_Mappings, White_Box_Definitions | |||
| 2014年07月30日 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2014年02月18日 | CWE Content Team | MITRE | |
| updated Potential_Mitigations, References | |||
| 2013年02月21日 | CWE Content Team | MITRE | |
| updated Observed_Examples | |||
| 2012年10月30日 | CWE Content Team | MITRE | |
| updated Potential_Mitigations | |||
| 2012年05月11日 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2011年06月01日 | CWE Content Team | MITRE | |
| updated Common_Consequences, Relationships, Taxonomy_Mappings | |||
| 2011年03月29日 | CWE Content Team | MITRE | |
| updated Alternate_Terms | |||
| 2010年12月13日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples, Name | |||
| 2010年06月21日 | CWE Content Team | MITRE | |
| updated Other_Notes, Potential_Mitigations | |||
| 2010年02月16日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2009年10月29日 | CWE Content Team | MITRE | |
| updated Modes_of_Introduction, Other_Notes | |||
| 2009年07月27日 | CWE Content Team | MITRE | |
| updated White_Box_Definitions | |||
| 2009年07月17日 | KDM Analytics | ||
| Improved the White_Box_Definition | |||
| 2009年05月27日 | CWE Content Team | MITRE | |
| updated Name | |||
| 2009年03月10日 | CWE Content Team | MITRE | |
| updated Other_Notes | |||
| 2008年10月14日 | CWE Content Team | MITRE | |
| updated Description | |||
| 2008年09月08日 | CWE Content Team | MITRE | |
| updated Applicable_Platforms, Common_Consequences, Relationships, Other_Notes, References, Relationship_Notes, Taxonomy_Mappings, Terminology_Notes | |||
| 2008年08月15日 | Veracode | ||
| Suggested OWASP Top Ten 2004 mapping | |||
| 2008年08月01日 | KDM Analytics | ||
| added/updated white box definitions | |||
| 2008年07月01日 | Eric Dalci | Cigital | |
| updated Time_of_Introduction | |||
| Previous Entry Names | |||
| Change Date | Previous Entry Name | ||
| 2008年04月11日 | Memory Leak | ||
| 2009年05月27日 | Failure to Release Memory Before Removing Last Reference (aka 'Memory Leak') | ||
| 2010年12月13日 | Failure to Release Memory Before Removing Last Reference ('Memory Leak') | ||
| 2019年01月03日 | Improper Release of Memory Before Removing Last Reference ('Memory Leak') | ||
| 2019年06月20日 | Improper Release of Memory Before Removing Last Reference | ||
Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2025, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.