Closed hangingman closed 2 years ago
cpputestでユニットテストをするとmemory leakを指摘される
../test/exp_suite.cpp:123: error: Failure in TEST(exp_suite, testCalc) Memory leak(s) found. Alloc num (52) Leak size: 16 Allocated at: <unknown> and line: 0. Type: "new" Memory: <0x55cf60fa8b90> Content: 0000: c8 ca ef 5f cf 55 00 00 40 84 fa 60 cf 55 00 00 |..._.U..@..`.U..| Alloc num (51) Leak size: 8 Allocated at: <unknown> and line: 0. Type: "new" Memory: <0x55cf60fa8440> Content: 0000: a8 bd ef 5f cf 55 00 00 |..._.U..| Total number of leaks: 2
yyrestart
fmemopen
workaround
nask_statements = R"( blah blah blah )"; std::unique_ptr<Driver> d(new Driver(false, false)); FILE* stream = fmemopen(&nask_statements, strlen(nask_statements), "r"); d->Parse<Program>(stream, "test.img"); fclose(stream);
https://github.com/CppCodeReviewers/Covariant-Return-Types-and-Smart-Pointers
振り返るとメモリーリークの原因はすべてC++のclassのメンバ変数をnewしながらも C++のclassのdestructorで開放していないことに起因していた
cpputestでユニットテストをするとmemory leakを指摘される
ワークアラウンド
原因と思われるところ(これは修正済みだったが参考のため残す)
yyrestart
の呼び方がおかしい模様fmemopen
を使うことでとりあえず回避できるworkaround