#3991 false positive: Memory leak (allocation function returns success/failed code). Add testcase. Issue had been fixed in 1.69 already

This commit is contained in:
Alexander Mai 2015-07-25 18:50:27 +02:00
parent 92b867dd2c
commit a36b544995
1 changed files with 17 additions and 0 deletions

View File

@ -361,6 +361,7 @@ private:
TEST_CASE(c_code);
TEST_CASE(gnucfg);
TEST_CASE(trac3991);
}
std::string getcode(const char code[], const char varname[], bool classfunc=false) {
@ -4269,6 +4270,22 @@ private:
check(code, &settings);
ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout.str());
}
void trac3991() {
check("int read_chunk_data(char **buffer) {\n"
" *buffer = (char *)malloc(chunk->size);\n"
" if (*buffer == NULL)\n"
" return -1;\n"
" return 0;\n"
"}\n"
"void printf_chunk_recursive() {\n"
" UINT8 *data = NULL;\n"
" int avierr = read_chunk_data(&data);\n"
" if (avierr == 0)\n"
" free(data);\n"
"}", nullptr, true);
ASSERT_EQUALS("", errout.str());
}
};
static TestMemleakInFunction testMemleakInFunction;