File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2628,6 +2628,34 @@ class TestMemleakNoVar : public TestFixture {
26282628 " [test.cpp:7:12]: (error) Allocation with f2, assert doesn't release it. [leakNoVarFunctionCall]\n "
26292629 " [test.cpp:8:12]: (error) Allocation with f3, assert doesn't release it. [leakNoVarFunctionCall]\n " ,
26302630 errout_str ());
2631+
2632+ check (" struct S {\n "
2633+ " explicit S(int fd) { m_fd = fd; }\n "
2634+ " ~S() { if (m_fd >= 0) close(m_fd); }\n "
2635+ " int m_fd = -1;\n "
2636+ " };\n "
2637+ " S g(char *name) { return S(mkostemp(name, 0)); }\n " );
2638+ ASSERT_EQUALS (" " ,
2639+ errout_str ());
2640+
2641+ check (" struct S {\n "
2642+ " explicit S(int fd) { m_fd = fd; }\n "
2643+ " ~S() {} // no close(...) \n "
2644+ " int m_fd = -1;\n "
2645+ " };\n "
2646+ " S g(char *name) { return S(mkostemp(name, 0)); }\n " );
2647+ ASSERT_EQUALS (" [test.cpp:6:28]: (error) Allocation with mkostemp, S doesn't release it. [leakNoVarFunctionCall]\n " ,
2648+ errout_str ());
2649+
2650+ check (" struct S {\n "
2651+ " explicit S(int fd) : x(1 + 2), m_fd(fd) {}\n "
2652+ " ~S() { if (m_fd >= 0) close(m_fd); }\n "
2653+ " int m_fd = -1;\n "
2654+ " int x;\n "
2655+ " };\n "
2656+ " S g(char *name) { return S(mkostemp(name, 0)); }\n " );
2657+ ASSERT_EQUALS (" " ,
2658+ errout_str ());
26312659 }
26322660
26332661 void missingAssignment () {
You can’t perform that action at this time.
0 commit comments