Skip to content

Commit 4f44a5a

Browse files
authored
Fix #13356: FP resourceLeak with greater-than comparison (danmar#7047)
1 parent fc6e9d3 commit 4f44a5a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static constexpr int NEW_ARRAY = -2;
5757
static constexpr int NEW = -1;
5858

5959
static const std::array<std::pair<std::string, std::string>, 4> alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}};
60-
static const std::array<std::pair<std::string, std::string>, 4> alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}};
60+
static const std::array<std::pair<std::string, std::string>, 5> alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}, {">", "-1"}}};
6161

6262
static bool isAutoDeallocType(const Type* type) {
6363
if (!type || !type->classScope)

test/testleakautovar.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,7 @@ class TestLeakAutoVarPosix : public TestFixture {
34253425
TEST_CASE(memleak_getline);
34263426
TEST_CASE(deallocuse_fdopen);
34273427
TEST_CASE(doublefree_fdopen); // #12781
3428+
TEST_CASE(memleak_open); // #13356
34283429
}
34293430

34303431
void memleak_getline() {
@@ -3466,6 +3467,17 @@ class TestLeakAutoVarPosix : public TestFixture {
34663467
"}\n");
34673468
ASSERT_EQUALS("", errout_str());
34683469
}
3470+
3471+
void memleak_open() { // #13356
3472+
check("int f() {\n"
3473+
" int fd = open(\"abc \", O_RDONLY);\n"
3474+
" if (fd > -1) {\n"
3475+
" return fd;\n"
3476+
" }\n"
3477+
" return -1;\n"
3478+
"}\n");
3479+
ASSERT_EQUALS("", errout_str());
3480+
}
34693481
};
34703482

34713483
REGISTER_TEST(TestLeakAutoVarPosix)

0 commit comments

Comments
 (0)