Skip to content

Commit

Permalink
Fixed danmar#1949: assert() hides memory leaks
Browse files Browse the repository at this point in the history
Added separate unit-test (trac1949), initially broken to highlight the error and added "assert" to call_func_white_list.

Left TestMemleakInFunction::call_func() as is, as this wouldn't highlight the actual problem.
  • Loading branch information
johnsyweb committed Sep 27, 2010
1 parent cdecbe2 commit 6a52538
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CheckMemoryLeakStructMember instance3;
// This list needs to be alphabetically sorted so we can run bsearch on it
static const char * const call_func_white_list[] =
{
"asctime", "asctime_r", "asprintf", "atof", "atoi", "atol", "clearerr"
"asctime", "asctime_r", "asprintf", "assert", "atof", "atoi", "atol", "clearerr"
, "ctime", "ctime_r", "delete", "fchmod", "fclose", "fcntl"
, "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets"
, "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek"
Expand Down
19 changes: 19 additions & 0 deletions test/testmemleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ class TestMemleakInFunction : public TestFixture

// setjmp/longjmp..
TEST_CASE(jmp);

TEST_CASE(trac1949);
}


Expand Down Expand Up @@ -2985,6 +2987,23 @@ class TestMemleakInFunction : public TestFixture
"}\n");
ASSERT_EQUALS("", errout.str());
}

void trac1949()
{
check("\n"
"\n"
"int fn()\n"
"{\n"
"char * buff = new char[100];\n"
"assert (buff);\n"
"\n"
"\n"
"\n"
"return 0;\n"
"}\n"
);
ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: buff\n", errout.str());
}
};

static TestMemleakInFunction testMemleakInFunction;
Expand Down

0 comments on commit 6a52538

Please sign in to comment.