From a5674182bb4194a1e167ac807630534b54a3d9ac Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Feb 2022 12:52:10 +0100 Subject: [PATCH] Add test for #5473 (#3831) --- test/testleakautovar.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 77aec7a5a..ca62cec7d 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -160,6 +160,7 @@ private: TEST_CASE(ifelse20); // #10182 TEST_CASE(ifelse21); TEST_CASE(ifelse22); // #10187 + TEST_CASE(ifelse23); // #5473 // switch TEST_CASE(switch1); @@ -1709,6 +1710,13 @@ private: ASSERT_EQUALS("", errout.str()); } + void ifelse23() { // #5473 + check("void f() {\n" + " if (FILE* fp = fopen(\"x\", \"r\")) {}\n" + "}\n"); + ASSERT_EQUALS("[test.c:2]: (error) Resource leak: fp\n", errout.str()); + } + void switch1() { check("void f() {\n" " char *p = 0;\n"