windows library: Add _malloca/_freea and _alloca configuration with tests (#1071)

This commit is contained in:
Sebastian 2018-01-30 16:40:38 +01:00 committed by GitHub
parent 79bb91179b
commit c62abee07a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

View File

@ -1171,6 +1171,11 @@
<alloc>CoTaskMemAlloc</alloc>
<dealloc>CoTaskMemFree</dealloc>
</memory>
<memory>
<alloc>_malloca</alloc>
<!-- Do not add _alloca here. It is automatically freed! -->
<dealloc>_freea</dealloc>
</memory>
<function name="RtlCompareMemory">
<noreturn>false</noreturn>
<leak-ignore/>
@ -4132,6 +4137,35 @@ HFONT CreateFont(
<not-bool/>
</arg>
</function>
<!--void *_malloca(
size_t size);-->
<function name="_malloca">
<returnValue type="void *"/>
<noreturn>false</noreturn>
<arg nr="1">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<!--void *_alloca(
size_t size);-->
<function name="_alloca">
<returnValue type="void *"/>
<noreturn>false</noreturn>
<use-retval/>
<arg nr="1">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<!--void _freea(
void *memblock);-->
<function name="_freea">
<noreturn>false</noreturn>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<podtype name="LARGE_INTEGER" sign="s" size="8"/>
<podtype name="POINTER_SIGNED" sign="s"/>
<podtype name="POINTER_UNSIGNED" sign="u"/>

View File

@ -78,6 +78,12 @@ void validCode()
ResetEvent(event);
CloseHandle(event);
}
void *pMem1 = _malloca(1);
_freea(pMem1);
// Memory from _alloca must not be freed
void *pMem2 = _alloca(10);
memset(pMem2, 0, 10);
}
void bufferAccessOutOfBounds()
@ -134,6 +140,13 @@ void nullPointer()
SetEvent(hEvent);
}
void memleak_malloca()
{
// cppcheck-suppress unreadVariable
void *pMem = _malloca(10);
// cppcheck-suppress memleak
}
void resourceLeak_CreateSemaphoreA()
{
HANDLE hSemaphore;
@ -248,6 +261,11 @@ void ignoredReturnValue()
OpenEvent(EVENT_ALL_ACCESS, FALSE, L"testevent");
// cppcheck-suppress leakReturnValNotUsed
CreateEventEx(NULL, L"test", CREATE_EVENT_INITIAL_SET, EVENT_MODIFY_STATE);
// cppcheck-suppress leakReturnValNotUsed
_malloca(10);
// cppcheck-suppress ignoredReturnValue
_alloca(5);
}
void invalidFunctionArg()
@ -281,6 +299,13 @@ void invalidFunctionArg()
// cppcheck-suppress invalidFunctionArg
HINSTANCE hInstLib = LoadLibraryEx(L"My.dll", 1, 0);
FreeLibrary(hInstLib);
// cppcheck-suppress invalidFunctionArg
void *pMem = _malloca(-1);
_freea(pMem);
// cppcheck-suppress unreadVariable
// cppcheck-suppress invalidFunctionArg
pMem = _alloca(-5);
}
void uninitvar()