Fixed #6311: Add support for GNU get_current_dir_name().

This commit is contained in:
Martin Ettl 2015-01-11 10:12:39 +01:00
parent 6f000fb16b
commit 37c89a6b70
2 changed files with 24 additions and 0 deletions

7
cfg/gnu.cfg Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<def format="1">
<memory>
<dealloc>free</dealloc>
<alloc init="true">get_current_dir_name</alloc>
</memory>
</def>

View File

@ -369,6 +369,8 @@ private:
// test that the cfg files are configured correctly
TEST_CASE(posixcfg);
TEST_CASE(posixcfg_mmap);
TEST_CASE(gnucfg);
}
std::string getcode(const char code[], const char varname[], bool classfunc=false) {
@ -4272,6 +4274,21 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
}
void gnucfg() {
Settings settings;
settings.standards.posix = true;
LOAD_LIB_2(settings.library, "gnu.cfg");
const char code[] = "void leak() {\n"
" char * p = get_current_dir_name();\n" // memory leak
"}\n"
"void noLeak() {\n"
" char * p = get_current_dir_name;\n"
" free(p)\n;"
"}";
check(code, &settings);
ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout.str());
}
// Test that posix.cfg is configured correctly
void posixcfg() {
Settings settings;