diff --git a/cfg/posix.cfg b/cfg/posix.cfg
index 78e6452b1..e499e17c6 100644
--- a/cfg/posix.cfg
+++ b/cfg/posix.cfg
@@ -8,31 +8,31 @@
false
false
- false
-
-
-
-
+ false
+
+
+
+
- false
-
-
-
-
+ false
+
+
+
+
false
false
- false
-
-
-
-
+ false
+
+
+
+
false
false
false
false
-
+ false
close
@@ -46,9 +46,13 @@
fdopendir
+
+ fclose
+ fdopen
+
+
pclose
popen
-
diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp
index 55ac0cadd..168a43209 100644
--- a/lib/checkmemoryleak.cpp
+++ b/lib/checkmemoryleak.cpp
@@ -184,6 +184,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
if (alloctype > 0) {
if (alloctype == settings1->library.dealloc("free"))
return Malloc;
+ if (alloctype == settings1->library.dealloc("fclose"))
+ return File;
return Library::ismemory(alloctype) ? OtherMem : OtherRes;
}
}
@@ -612,7 +614,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::liststr()) != noreturn.end() && tok->strAt(-1) != "=")
return "exit";
- if (varid > 0 && (getAllocationType(tok, varid) != No || getReallocationType(tok, varid) != No || getDeallocationType(tok, varid) != No))
+ if (varid > 0 && (getReallocationType(tok, varid) != No || getDeallocationType(tok, varid) != No))
return 0;
if (callstack.size() > 2)
diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp
index de1826867..f3f4863fb 100644
--- a/test/testmemleak.cpp
+++ b/test/testmemleak.cpp
@@ -330,7 +330,6 @@ private:
TEST_CASE(getc_function);
TEST_CASE(open_function);
- TEST_CASE(open_fdopen);
TEST_CASE(creat_function);
TEST_CASE(close_function);
TEST_CASE(fd_functions);
@@ -3876,19 +3875,6 @@ private:
ASSERT_EQUALS("", errout.str());
}
- void open_fdopen() {
- // Ticket #2830
- Settings settings;
- settings.standards.posix = true;
- check("void f(const char *path)\n"
- "{\n"
- " int fd = open(path, O_RDONLY);\n"
- " FILE *f = fdopen(fd, x);\n"
- " fclose(f);\n"
- "}", &settings);
- ASSERT_EQUALS("", errout.str());
- }
-
void creat_function() {
Settings settings;
settings.standards.posix = true;
@@ -4267,6 +4253,20 @@ private:
check(code2, &settings);
ASSERT_EQUALS("", errout.str());
+ // Ticket #2830
+ check("void f(const char *path) {\n"
+ " int fd = open(path, O_RDONLY);\n"
+ " FILE *f = fdopen(fd, x);\n"
+ " fclose(f);\n"
+ "}", &settings);
+ ASSERT_EQUALS("", errout.str());
+
+ // Ticket #1416
+ check("void f(void) {\n"
+ " FILE *f = fdopen(0, \"r\");\n"
+ "}", &settings);
+ ASSERT_EQUALS("[test.cpp:3]: (error) Resource leak: f\n", errout.str());
+
LOAD_LIB_2(settings.library, "gtk.cfg");
check("void f(char *a) {\n"