我试图让 clang++ 告诉我有内存泄漏。我尝试了 scan-build 但它没有报告任何内容。如何让 llvm/clang 警告我这个问题?
#include <iostream>
int main() {
int *a = new int;
*a = 8;
std::cout<< a << std::endl;
}
我试图让 clang++ 告诉我有内存泄漏。我尝试了 scan-build 但它没有报告任何内容。如何让 llvm/clang 警告我这个问题?
#include <iostream>
int main() {
int *a = new int;
*a = 8;
std::cout<< a << std::endl;
}
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.
因为 int 太小,程序有一个“保留部分”,所以对于小对象不需要扩展内存区域,尝试应用 1024 * 1024 * 10 然后检查结果