C++ leaks in case of exception even by using smart pointers
问题 I am new to the smart pointers world. I've done my reading and all of them stated that smart pointers will avoid leaking memory even when the program will exit after encountering an exception. I wrote down a simple program to try this out, but Valgrind is telling me my program is leaking memory (three allocs and only one free). This is the source code: #include <iostream> #include <memory> using namespace std; int main() { auto_ptr<int> ptr_int(new int(5)); throw std::bad_alloc(); cout <<