double freeing of freed memory
2017-05-15 13:12
489 查看
最近在客户那里改用klockwork分析出的问题,遇到了这个问题:Double freeing of freed memory may be in class 'DriverInfo'. copy constructor and operator= is not defined。
自己写了个例子
#include <iostream>
class MyData
{
public:
MyData()
{
myData = new int;
printf("Created data: 0x%08X\n", myData);
}
~MyData()
{
printf("Destroying data: 0x%08X\n", myData);
delete myData;
}
private:
int* myData;
};
int main(int argc, char* argv[])
{
MyData test1;
MyData test2;
test2 = test1;
MyData test3(test1);
}
----------------------------------------------------------------------------------------------------------------
输出结果:
Created data: 0x00551d30
Created data: 0x00551d70
Destroying data: 0x00551D30
Destroying data: 0x00551D30
挂了。。。
这里有内存泄漏(0x00551d70)和多次释放资源。这个问题本质上应该是深拷贝和浅拷贝的问题。
最近在客户那里改用klockwork分析出的问题,遇到了这个问题:Double freeing of freed memory may be in class 'DriverInfo'. copy constructor and operator= is not defined。
自己写了个例子
#include <iostream>
class MyData
{
public:
MyData()
{
myData = new int;
printf("Created data: 0x%08X\n", myData);
}
~MyData()
{
printf("Destroying data: 0x%08X\n", myData);
delete myData;
}
private:
int* myData;
};
int main(int argc, char* argv[])
{
MyData test1;
MyData test2;
test2 = test1;
MyData test3(test1);
}
----------------------------------------------------------------------------------------------------------------
输出结果:
Created data: 0x00551d30
Created data: 0x00551d70
Destroying data: 0x00551D30
Destroying data: 0x00551D30
挂了。。。
这里有内存泄漏(0x00551d70)和多次释放资源。这个问题本质上应该是深拷贝和浅拷贝的问题。
相关文章推荐
- xen domu hangs on boot:Freeing unused kernel memory: 200k freed
- Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free
- "Director Player 6.0 - This program requires at least 3MB of free virtual memory to run."
- 释放内存free()错误:CRT detected that the application wrote to memory after end of heap buffer:内存访问违规
- MS Internet Explorer Recordset Double Free Memory Exploit (MS07-009)
- 启动内核,运行到Freeing init memory: 120K卡死的解决方法
- freeing unused kernel memory 2.6.19问题查找过程
- 每日一命令(13)free - (Display amount of free and used memory in the system)
- MS Internet Explorer Recordset Double Free Memory Exploit (MS07-009)
- java.lang.OutOfMemoryError: Failed to allocate a 3110419 byte allocation with 741152 free bytes and
- [ 1.309420] Freeing initrd memory: 484K 卡死问题解决办法
- Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free
- memory leak & double free如何排查?
- yaffs启动卡死在Freeing init Memory 120K处的解决方法-Linux一直常见错误解决篇
- Caused by: java.lang.OutOfMemoryError: Failed to allocate a 29433932 byte allocation with 14683576 free bytes and 14MB
- 6220: Permanent data partition free space insufficient to allocate 33296 bytes of memory
- Permanent data region free space insufficient to allocate 64792 bytes of memory
- arm文件系统 freeing init memory没有再往下执行
- java.lang.OutOfMemoryError:GC overhead limit exceeded
- 关于GDI+产生OutOfMemory问题及GDI+用法概要