Visual Studio VC 的静态代码内存泄漏检测++
有没有一种方法可以使用静态分析工具来检测像这样的简单内存泄漏?我无法更改代码以包含运行时内存泄漏检测中使用的典型包含(struc1 是带有一些字段的简单结构)。
void noRelease(void)
{
struc1 *memoryLeak;
memoryLeak = (struc1 *) malloc(sizeof struc1);
if (NULL != memoryLeak)
{
memoryLeak->a=3;
}
}
VSTS(Visual Studio Team System)检测到由于异常导致的内存泄漏,但无法看到这种简单的泄漏。
任何想法都会非常有帮助。 多谢。
is there a way to detect simple memory leaks like this one with a static analysis tool? I cannot change the code to include the tipical includes used in runtime memory leak detection (struc1 is a simple structure with some fields).
void noRelease(void)
{
struc1 *memoryLeak;
memoryLeak = (struc1 *) malloc(sizeof struc1);
if (NULL != memoryLeak)
{
memoryLeak->a=3;
}
}
VSTS (Visual Studio Team System) detects memory leaks due to exceptions but is not able to see this simple leak.
Any ideas will be very helpful.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CPPCheck 进行静态代码分析并检测此类泄漏
http://cppcheck.sourceforge.net/
CPPCheck does static code analysis and detect those kind of leaks
http://cppcheck.sourceforge.net/
嗯... Coverity 可以做到这一点,但你必须卖掉你的房子来支付费用。
我曾经编写过一个静态分析器,用于检查在给定函数范围内是否调用了一对函数。我使用了一个静态分析 API,该 API 附带一个由 scitools 制作的名为“Understand 4 C++”的程序。
www.scitools.com
我使用包装 C API 的 托管 API(我编写的)编写了搜索器/scrutinzer。注意:然而,Understanding 4 c++ 不是免费的。
不管怎样,我编写的那个工具会检测到上面代码中缺少 free 。它并不比这聪明多少。如果指针在其他地方被释放,它就找不到它。
Hm... Coverity could do that but you would have to sell your house to pay for it.
I once wrote a static analyzer that checks if a pair of functions are called in a given function scope. I used a static analysis API that comes with a program called 'Understand 4 C++' made by scitools.
www.scitools.com
I wrote the searcher/scrutinzer using a managed API (that I wrote) that wraps their C API. Note: However Understand 4 c++ is not free.
Anyways, that tool I wrote would detect the lack of free in the code above. it was not much smarter than that. If the pointer was free'd somewhere else, it would not find it.