Skip to content

Commit 25fb983

Browse files
committed
Add test for #4638 FN memleak (pointer converted to bool on return)
1 parent dd01ff1 commit 25fb983

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/testleakautovar.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class TestLeakAutoVar : public TestFixture {
181181
TEST_CASE(return10);
182182
TEST_CASE(return11); // #13098
183183
TEST_CASE(return12); // #12238
184+
TEST_CASE(return13);
184185

185186
// General tests: variable type, allocation type, etc
186187
TEST_CASE(test1);
@@ -2838,6 +2839,22 @@ class TestLeakAutoVar : public TestFixture {
28382839
ASSERT_EQUALS("", errout_str());
28392840
}
28402841

2842+
void return13() { // #4638
2843+
CheckOptions options;
2844+
options.cpp = true;
2845+
check("bool f() {\n"
2846+
" int* p = new int;\n"
2847+
" return p;\n"
2848+
"}\n"
2849+
"bool g() {\n"
2850+
" void* p = malloc(4);\n"
2851+
" return p;\n"
2852+
"}\n", options);
2853+
ASSERT_EQUALS("[test.cpp:3:5]: (error) Memory leak: p [memleak]\n"
2854+
"[test.cpp:7:5]: (error) Memory leak: p [memleak]\n",
2855+
errout_str());
2856+
}
2857+
28412858
void test1() {
28422859
check("void f(double*&p) {\n" // 3809
28432860
" p = malloc(0x100);\n"

0 commit comments

Comments
 (0)