Logo
-

Byte Open Security

(ByteOS Network)

Log In

Sign Up

ByteOS

Security
Vulnerability Details
Registries
Custom Views
Weaknesses
Attack Patterns
Filters & Tools
CWE-401:Missing Release of Memory after Effective Lifetime
Weakness ID:401
Version:v4.17
Weakness Name:Missing Release of Memory after Effective Lifetime
Vulnerability Mapping:Allowed
Abstraction:Variant
Structure:Simple
Status:Draft
Likelihood of Exploit:Medium
DetailsContent HistoryObserved CVE ExamplesReports
▼Description

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

diagram
▼Extended Description

▼Alternate Terms
Memory Leak

▼Relationships
Relevant to the view"Research Concepts - (1000)"
NatureMappingTypeIDName
ChildOfAllowedB772Missing Release of Resource after Effective Lifetime
ParentOfAllowedB390Detection of Error Condition Without Action
Nature: ChildOf
Mapping: Allowed
Type: Base
ID: 772
Name: Missing Release of Resource after Effective Lifetime
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 390
Name: Detection of Error Condition Without Action
▼Memberships
NatureMappingTypeIDName
MemberOfProhibitedC3987PK - Code Quality
MemberOfProhibitedC730OWASP Top Ten 2004 Category A9 - Denial of Service
MemberOfProhibitedC861The CERT Oracle Secure Coding Standard for Java (2011) Chapter 18 - Miscellaneous (MSC)
MemberOfProhibitedC1152SEI CERT Oracle Secure Coding Standard for Java - Guidelines 49. Miscellaneous (MSC)
MemberOfProhibitedC1162SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
MemberOfProhibitedC1238SFP Primary Cluster: Failure to Release Memory
MemberOfProhibitedC1399Comprehensive Categorization: Memory Safety
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 398
Name: 7PK - Code Quality
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 730
Name: OWASP Top Ten 2004 Category A9 - Denial of Service
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 861
Name: The CERT Oracle Secure Coding Standard for Java (2011) Chapter 18 - Miscellaneous (MSC)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1152
Name: SEI CERT Oracle Secure Coding Standard for Java - Guidelines 49. Miscellaneous (MSC)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1162
Name: SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1238
Name: SFP Primary Cluster: Failure to Release Memory
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1399
Name: Comprehensive Categorization: Memory Safety
▼Tags
NatureMappingTypeIDName
MemberOfProhibitedBSBOSS-273Medium likelihood of exploit
MemberOfProhibitedBSBOSS-278Libraries or Frameworks Strategy
MemberOfProhibitedBSBOSS-313Reduce Performance (impact)
MemberOfProhibitedBSBOSS-314DoS: Resource Consumption (CPU) (impact)
MemberOfProhibitedBSBOSS-324DoS: Crash, Exit, or Restart (impact)
MemberOfProhibitedBSBOSS-327DoS: Resource Consumption (Memory) (impact)
MemberOfProhibitedBSBOSS-329DoS: Instability (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-273
Name: Medium likelihood of exploit
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-278
Name: Libraries or Frameworks Strategy
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-313
Name: Reduce Performance (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-314
Name: DoS: Resource Consumption (CPU) (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-324
Name: DoS: Crash, Exit, or Restart (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-327
Name: DoS: Resource Consumption (Memory) (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-329
Name: DoS: Instability (impact)
▼Relevant To View
Relevant to the view"Weaknesses Addressed by the SEI CERT Oracle Coding Standard for Java - (1133)"
NatureMappingTypeIDName
MemberOfProhibitedC1152SEI CERT Oracle Secure Coding Standard for Java - Guidelines 49. Miscellaneous (MSC)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1152
Name: SEI CERT Oracle Secure Coding Standard for Java - Guidelines 49. Miscellaneous (MSC)
Relevant to the view"Weaknesses Addressed by the SEI CERT C Coding Standard - (1154)"
NatureMappingTypeIDName
MemberOfProhibitedC1162SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1162
Name: SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
Relevant to the view"Software Fault Pattern (SFP) Clusters - (888)"
NatureMappingTypeIDName
MemberOfProhibitedC1238SFP Primary Cluster: Failure to Release Memory
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1238
Name: SFP Primary Cluster: Failure to Release Memory
Relevant to the view"Seven Pernicious Kingdoms - (700)"
NatureMappingTypeIDName
MemberOfProhibitedC3987PK - Code Quality
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 398
Name: 7PK - Code Quality
▼Background Detail

▼Common Consequences
ScopeLikelihoodImpactNote
AvailabilityN/ADoS: Crash, Exit, or RestartDoS: InstabilityDoS: Resource Consumption (CPU)DoS: Resource Consumption (Memory)

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.

OtherN/AReduce Performance
N/A
Scope: Availability
Likelihood: N/A
Impact: DoS: Crash, Exit, or Restart, DoS: Instability, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory)
Note:

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.

Scope: Other
Likelihood: N/A
Impact: Reduce Performance
Note:
N/A
▼Potential Mitigations
Phase:Implementation
Mitigation ID: MIT-41
Strategy: Libraries or Frameworks
Effectiveness:
Description:

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.

Note:


Phase:Architecture and Design
Mitigation ID:
Strategy:
Effectiveness:
Description:

Use an abstraction library to abstract away risky APIs. Not a complete solution.

Note:


Phase:Architecture and Design, Build and Compilation
Mitigation ID:
Strategy:
Effectiveness:
Description:

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.

▼Modes Of Introduction
Phase: Implementation
Note:

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.
▼Applicable Platforms
Languages
Class: C(Undetermined Prevalence)
Class: C++(Undetermined Prevalence)
▼Demonstrative Examples
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:

Language: ( code)
N/A

Language: C(Bad code)
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; }

▼Observed Examples
ReferenceDescription
CVE-2005-3119
Memory leak because function does not free() an element of a data structure.
CVE-2004-0427
Memory leak when counter variable is not decremented.
CVE-2002-0574
chain: reference count is not decremented, leading to memory leak in OS by sending ICMP packets.
CVE-2005-3181
Kernel uses wrong function to release a data structure, preventing data from being properly tracked by other code.
CVE-2004-0222
Memory leak via unknown manipulations as part of protocol test suite.
CVE-2001-0136
Memory leak via a series of the same command.
Reference: CVE-2005-3119
Description:
Memory leak because function does not free() an element of a data structure.
Reference: CVE-2004-0427
Description:
Memory leak when counter variable is not decremented.
Reference: CVE-2002-0574
Description:
chain: reference count is not decremented, leading to memory leak in OS by sending ICMP packets.
Reference: CVE-2005-3181
Description:
Kernel uses wrong function to release a data structure, preventing data from being properly tracked by other code.
Reference: CVE-2004-0222
Description:
Memory leak via unknown manipulations as part of protocol test suite.
Reference: CVE-2001-0136
Description:
Memory leak via a series of the same command.
▼Affected Resources
  • Memory
▼Functional Areas
  • Memory Management
▼Weakness Ordinalities
OrdinalityDescription
Resultant
N/A
Ordinality: Resultant
Description:
N/A
▼Detection Methods
Fuzzing
Detection Method ID:DM-13
Description:

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
Note:

N/A


Automated Static Analysis
Detection Method ID:DM-14
Description:

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
Note:

N/A

▼Vulnerability Mapping Notes
Usage:Allowed
Reason:Acceptable-Use
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.

Suggestions:
▼Notes
Relationship

This is often a resultant weakness due to improper handling of malformed data or early termination of sessions.

N/A

Terminology

"memory leak" has sometimes been used to describe other kinds of issues, e.g. for information leaks in which the contents of memory are inadvertently leaked (CVE-2003-0400 is one such example of this terminology conflict).

N/A

▼Taxonomy Mappings
Taxonomy NameEntry IDFitEntry Name
PLOVERN/AN/AMemory leak
7 Pernicious KingdomsN/AN/AMemory Leak
CLASPN/AN/AFailure to deallocate data
OWASP Top Ten 2004A9CWE More SpecificDenial of Service
CERT C Secure CodingMEM31-CExactFree dynamically allocated memory when no longer needed
The CERT Oracle Secure Coding Standard for Java (2011)MSC04-JN/ADo not leak memory
Software Fault PatternsSFP14N/AFailure to Release Resource
OMG ASCPEMASCPEM-PRF-14N/AN/A
Taxonomy Name: PLOVER
Entry ID: N/A
Fit: N/A
Entry Name: Memory leak
Taxonomy Name: 7 Pernicious Kingdoms
Entry ID: N/A
Fit: N/A
Entry Name: Memory Leak
Taxonomy Name: CLASP
Entry ID: N/A
Fit: N/A
Entry Name: Failure to deallocate data
Taxonomy Name: OWASP Top Ten 2004
Entry ID: A9
Fit: CWE More Specific
Entry Name: Denial of Service
Taxonomy Name: CERT C Secure Coding
Entry ID: MEM31-C
Fit: Exact
Entry Name: Free dynamically allocated memory when no longer needed
Taxonomy Name: The CERT Oracle Secure Coding Standard for Java (2011)
Entry ID: MSC04-J
Fit: N/A
Entry Name: Do not leak memory
Taxonomy Name: Software Fault Patterns
Entry ID: SFP14
Fit: N/A
Entry Name: Failure to Release Resource
Taxonomy Name: OMG ASCPEM
Entry ID: ASCPEM-PRF-14
Fit: N/A
Entry Name: N/A
▼Related Attack Patterns
IDName
▼References
Reference ID: REF-18
Title: The CLASP Application Security Process
Author: Secure Software, Inc.
Section:
Publication:
Publisher:
Edition:
URL:https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf
URL Date:2024-11-17
Day:N/A
Month:N/A
Year:2005
Reference ID: REF-390
Title: How to Break Software Security
Author: J. Whittaker, H. Thompson
Section:
Publication:
Publisher:Addison Wesley
Edition:
URL:
URL Date:
Day:N/A
Month:N/A
Year:2003
Reference ID: REF-391
Title: Transitioning to ARC Release Notes
Author: iOS Developer Library
Section:
Publication:
Publisher:
Edition:
URL:https://developer.apple.com/library/archive/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
URL Date:2023-04-07
Day:08
Month:08
Year:2013
Reference ID: REF-959
Title: Automated Source Code Performance Efficiency Measure (ASCPEM)
Author: Object Management Group (OMG)
Section: ASCPEM-PRF-14
Publication:
Publisher:
Edition:
URL:https://www.omg.org/spec/ASCPEM/
URL Date:2023-04-07
Day:N/A
Month:01
Year:2016
Details not found