Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/testmemleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class TestMemleakInFunction : public TestFixture {
TEST_CASE(dealloc_use);
TEST_CASE(dealloc_use_2);
TEST_CASE(dealloc_use_3);
TEST_CASE(dealloc_use_4); // #7960

// free a free'd pointer
TEST_CASE(freefree1);
Expand Down Expand Up @@ -3199,6 +3200,21 @@ class TestMemleakInFunction : public TestFixture {
ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str());
}

void dealloc_use_4() { // #7960
check("class SR {\n"
"public:\n"
" void dostuff();\n"
" int* m_data;\n"
"};\n"
"void SR::dostuff() {\n"
" SR sr;\n"
" delete m_data;\n"
" sr.m_data = new SVec;\n"
" *m_data = 123;\n"
"}");
ASSERT_EQUALS("", errout.str());
}

void freefree1() {
check("void foo()\n"
"{\n"
Expand Down
15 changes: 15 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class TestOther : public TestFixture {

TEST_CASE(redundantVarAssignment);
TEST_CASE(redundantVarAssignment_7133);
TEST_CASE(redundantVarAssignment_stackoverflow);
TEST_CASE(redundantMemWrite);

TEST_CASE(varFuncNullUB);
Expand Down Expand Up @@ -5172,6 +5173,20 @@ class TestOther : public TestFixture {

}

void redundantVarAssignment_stackoverflow() {
check("typedef struct message_node {\n"
" char code;\n"
" size_t size;\n"
" struct message_node *next, *prev;\n"
"} *message_list;\n"
"static message_list remove_message_from_list(message_list m) {\n"
" m->prev->next = m->next;\n"
" m->next->prev = m->prev;\n"
" return m->next;\n"
"}");
ASSERT_EQUALS("", errout.str());
}

void redundantMemWrite() {
// Simple tests
check("void f() {\n"
Expand Down