1

我试图让 clang++ 告诉我有内存泄漏。我尝试了 scan-build 但它没有报告任何内容。如何让 llvm/clang 警告我这个问题?

#include <iostream>

int main() {
        int *a = new int;
        *a = 8;
        std::cout<< a << std::endl;
}
4

2 回答 2

0

False-positive pruning usually leads to removing all leaks that originate from main(), since the program will exit anyway. Try analyzing the same code, but in a different function.

于 2013-10-03T20:03:22.773 回答
0

因为 int 太小,程序有一个“保留部分”,所以对于小对象不需要扩展内存区域,尝试应用 1024 * 1024 * 10 然后检查结果

于 2014-03-14T08:07:24.850 回答