Closed edonyzpc closed 7 years ago
Looks like a bug to me. Not in the library though, this would only effect the test code and the resource manager (which already has a lot of existing problems).
@flihp Thank you for confirmation. And this function is not in the library ?
TSS2_SYS_CONTEXT *InitSysContext(
UINT16 maxCommandSize,
TSS2_TCTI_CONTEXT *tctiContext,
TSS2_ABI_VERSION *abiVersion
)
I misspoke there. Clarification: the InitSysContext is a convenience function used in the test programs and the resorucemgr. It's not part of the SAPI spec. We shouldn't be packaging / exposing it through the libraries we distribute. Likely we are though. I made an issue a long time back to cleanup symbols that we shouldn't be exposing in the libraries but that needs to be decomposed to actionable issues.
Either way this code needs to be fixed. The symbol stuff will be cleaned up in the next release.
@edonyM I threw together a PR over lunch. Wanna take a look for me and ACK if it's what you had in mind? https://github.com/01org/TPM2.0-TSS/pull/333
@flihp I have checked you PR, it seems good to fix this bug. But I think there is another one you might miss, in function UINT32 WINAPI SockServer( LPVOID servStruct )
[LINE 2708 - LINE 2712]
if( cmdServerStruct->connectSock == INVALID_SOCKET )
{
printf( "Accept failed. Error is 0x%x\n", WSAGetLastError() );
continue;
}
This judgement means if fail to connect with the socket, connect it again. In the do{...}while(...)
, you are applying for memory and do not release it before you re-connect.
Good catch. The logic in this function is still pretty ugly but I think this takes care of the possible memory leak.
I have checked your PR again and that's it. Personally, they were fixed. Of course, look forward to the improvement of resourcemgr.
Thank you for your time. Close the issue.
Source code above in
InitSysContext
function in fileTPM2.0-TSS/common/syscontext.c
lead to memory leakage for not free the malloc memory of variablesysContext
.P.S. Also in file
TPM2.0-TSS/resourcemgr/resourcemgr.c
, there is the same problem inSockServer
function and the source codes are as follows. In this while loops, resourcemgr will apply for the memory unlimited if failed to connect to the socket or failed to detach the thread.