C++/clang analyzer memory leaks?

无人久伴 提交于 2019-12-08 08:51:09

问题


I'm trying to get clang++ to tell me there is a memory leak. I tried scan-build but it reported nothing. How do I get llvm/clang to warn me of this problem?

#include <iostream>

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

回答1:


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.




回答2:


Because int is too small, there is something like one "reserved section" for program so for small object no need to extend memory area, try to apply 1024 * 1024 * 10 then check the result



来源:https://stackoverflow.com/questions/19149239/c-clang-analyzer-memory-leaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!