From 2f46e57311ca8a7aacd52e637066ed6f2f4484ed Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 17 Feb 2022 16:22:30 +0100 Subject: [PATCH] Add leak-ignore for fopen_s(), test cases (#3839) * Add leak-ignore for fopen_s(), test cases * Format --- cfg/std.cfg | 1 + test/testleakautovar.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/cfg/std.cfg b/cfg/std.cfg index 69cb06145..79dd597e0 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1867,6 +1867,7 @@ false + diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 6e7d218c5..5578a73fa 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -1741,6 +1741,24 @@ private: "}\n", s); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: temp\n", errout.str()); + check("FILE* f() {\n" + " char* temp = strdup(\"temp.txt\");\n" + " FILE* fp = NULL;\n" + " fopen_s(&fp, temp, \"rt\");\n" + " return fp;\n" + "}\n", s); + ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: temp\n", errout.str()); + + check("void f() {\n" + " char* temp = strdup(\"temp.txt\");\n" + " FILE* fp = fopen(\"a.txt\", \"rb\");\n" + " if (fp)\n" + " freopen(temp, \"rt\", fp);\n" + "}\n", s); + ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: temp\n" + "[test.cpp:6]: (error) Resource leak: fp\n", + errout.str()); + check("FILE* f() {\n" " char* temp = strdup(\"temp.txt\");\n" " return fopen(temp, \"rt\");\n"