You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testleakautovar.cpp
+49Lines changed: 49 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -118,6 +118,7 @@ class TestLeakAutoVar : public TestFixture {
118
118
119
119
// handling function calls
120
120
TEST_CASE(functioncall1);
121
+
TEST_CASE(anonymousFunctionCall1);
121
122
122
123
// goto
123
124
TEST_CASE(goto1);
@@ -1910,6 +1911,54 @@ class TestLeakAutoVar : public TestFixture {
1910
1911
ASSERT_EQUALS("[test.cpp:4:1]: (error) Memory leak: b [memleak]\n", errout_str());
1911
1912
}
1912
1913
1914
+
voidanonymousFunctionCall1() { // #14990
1915
+
// function pointer
1916
+
check("void f(void (*fptr)(void *)) {\n"
1917
+
"void *buf = malloc(1);\n"
1918
+
"(*fptr)(buf);\n"
1919
+
"}\n");
1920
+
ASSERT_EQUALS("", errout_str());
1921
+
1922
+
// lambda
1923
+
check("void f() {\n"
1924
+
"auto x = [](void *ptr) { g(ptr) };\n"
1925
+
"void *p = malloc(1);\n"
1926
+
"(x)(p);\n"
1927
+
"}\n");
1928
+
ASSERT_EQUALS("", errout_str());
1929
+
1930
+
// Function returning a function pointer
1931
+
check("void f() {\n"
1932
+
" void *buf = malloc(1);\n"
1933
+
" get_function()(buf);\n"
1934
+
"}\n");
1935
+
ASSERT_EQUALS("", errout_str());
1936
+
1937
+
// Function returning a function pointer, passed as an arg to a normal
1938
+
// function
1939
+
check("void f() {\n"
1940
+
" void *buf = malloc(1);\n"
1941
+
" foo(get_function()(buf));\n"
1942
+
"}\n");
1943
+
ASSERT_EQUALS("[test.c:3:29]: (information) --check-library: Function foo() should have <noreturn> configuration [checkLibraryNoReturn]\n"
1944
+
"[test.c:4:1]: (information) --check-library: Function foo() should have <use>/<leak-ignore> configuration [checkLibraryUseIgnore]\n",
1945
+
errout_str());
1946
+
1947
+
// Function returning a function pointer, passed as an arg to another
1948
+
// function returning a function pointer
1949
+
check("void f() {\n"
1950
+
" void *buf = malloc(1);\n"
1951
+
" get_function()(get_function()(buf));\n"
1952
+
"}\n");
1953
+
ASSERT_EQUALS("", errout_str());
1954
+
1955
+
check("void f() {\n"
1956
+
" void *buf = malloc(1);\n"
1957
+
" get_function(buf)(get_function(NULL)(NULL));\n"
1958
+
"}\n");
1959
+
ASSERT_EQUALS("[test.c:4:1]: (information) --check-library: Function get_function() should have <use>/<leak-ignore> configuration [checkLibraryUseIgnore]\n", errout_str());
0 commit comments