Add leak-ignore for fopen_s(), test cases (#3839)

* Add leak-ignore for fopen_s(), test cases

* Format
This commit is contained in:
chrchr-github 2022-02-17 16:22:30 +01:00 committed by GitHub
parent bb8b9a8001
commit 2f46e57311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -1867,6 +1867,7 @@
<function name="fopen_s">
<returnValue type="errno_t"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-null/>
</arg>

View File

@ -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"