도구로 재현한다
LeakSanitizer나 Valgrind로 누수 stack trace를 얻고 입력을 고정한다.
누수는 delete를 잊은 줄 하나만의 문제가 아니다. 예외 경로, 순환 참조, 캐시 정책, C API 경계에서 소유권이 사라질 때 생긴다.
LeakSanitizer나 Valgrind로 누수 stack trace를 얻고 입력을 고정한다.
할당된 객체가 어느 컨테이너, 포인터, callback에 넘어갔는지 마지막 참조를 찾는다.
raw new/delete를 unique_ptr, vector, string, RAII wrapper로 바꿔 반복 누수를 차단한다.
using FilePtr = std::unique_ptr<FILE, decltype(&std::fclose)>;
FilePtr file(std::fopen(path.c_str(), "rb"), &std::fclose);
if (!file) throw std::runtime_error("open failed");