Open November20 opened 10 months ago
xiti18_10.cpp:
#include <vector> using std::vector; class iStack{ public: iStack(int capacity):top(0),stack(capacity){} private: int top; vector<int> stack; }; int main() { iStack *ps = new iStack(20); return 0; }
Compile command:
g++ -std=c++98 -O0 --ansi -fno-elide-constructors -Wall -fsanitize=address -fsanitize=undefined -g xiti18_10.cpp ; ASAN_OPTIONS=detect_leaks=1 ./a.out
Results:
------------run---------------- xiti18_10.cpp xiti18_10.cpp: In function ‘int main()’: xiti18_10.cpp:14:17: warning: unused variable ‘ps’ [-Wunused-variable] 14 | iStack *ps = new iStack(20); | ^~ ------------over--------------- return: 0
There is no delete here.How to deal with this problem?
This is a memory leak. Why can't it be analyzed?
xiti18_10.cpp:
Compile command:
Results:
There is no delete here.How to deal with this problem?