HobbyOSs / opennask

nask clone assembly, it can boot tiny OS with Linux
https://github.com/HobbyOSs/opennask/wiki/%E5%8B%95%E4%BD%9C%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF
GNU General Public License v3.0
20 stars 3 forks source link

bnfcにメモリリーク問題がある #42

Closed hangingman closed 2 years ago

hangingman commented 3 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

ワークアラウンド

原因と思われるところ(これは修正済みだったが参考のため残す)

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);
hangingman commented 2 years ago

https://github.com/CppCodeReviewers/Covariant-Return-Types-and-Smart-Pointers

hangingman commented 2 years ago

振り返るとメモリーリークの原因はすべてC++のclassのメンバ変数をnewしながらも C++のclassのdestructorで開放していないことに起因していた