CWE-762:不匹配的内存管理例程
View customized information:
The product attempts to return a memory resource to the system, but it calls a release function that is not compatible with the function that was originally used to allocate that resource.
This weakness can be generally described as mismatching memory management routines, such as:
When the memory management functions are mismatched, the consequences may be as severe as code execution, memory corruption, or program crash. Consequences and ease of exploit will vary depending on the implementation of the routines and the object being managed. ![]() ![]()
![]() ![]()
![]()
![]() 语言 C(不确定的患病率) C ++(不确定的患病率) ![]()
Example 1 此示例使用C ++中的新运算符分配Barobj对象,但是,程序员然后使用Free()对对象进行处理,这可能导致意外行为。
(不良代码)
Example Language:C ++
void foo(){
barobj *ptr = new barobj()
/* do some work with ptr here */ ... 免费(ptr); Instead, the programmer should have either created the object with one of the malloc family functions, or else deleted the object with the delete operator.
(good code)
Example Language:C ++
void foo(){
barobj *ptr = new barobj()
/* do some work with ptr here */ ... delete ptr; Example 2 In this example, the program does not use matching functions such as malloc/free, new/delete, and new[]/delete[] to allocate/deallocate the resource.
(不良代码)
Example Language:C ++
A类{
void foo(); };void a :: foo(){
int *ptr; }ptr =(int*)malloc(sizeof(int)); delete ptr; Example 3 在此示例中,该程序在非HEAP内存上调用delete []函数。
(不良代码)
Example Language:C ++
class A{
void foo(bool); };void A::foo(bool heap) {
int localArray[2] = { }
11,22 };int *p = localArray; 如果(堆){
p = new int [2]; }删除[] p;
![]()
Applicable Platform This weakness is possible in any programming language that allows manual management of memory.
More information is available — Please select a different filter.
|
Use of the Common Weakness Enumeration (CWE) and the associated references from this website are subject to the使用条款. CWE is sponsored by theU.S. Department of Homeland Security(DHS)网络安全和基础设施安全局(CISA),由国土安全系统工程和开发研究所(HSSEDI) which is operated bymanbetx客户端首页(MITRE). Copyright © 2006–2023, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation. |