kavika13/RemCom

CreateNamedPipes in RemComSvc.cpp leaks non-paged memory

JWindram opened this issue · 1 comments

For the un-modified RemCom, this is not an issue, as the RemComSvc service stops and uninstalls itself when the last client disconnects. However, if someone were to modify the source so that the stop and uninstall didn't happen (i.e. the service was left running), then if many commands were executed, eventually the non-paged pool would be exhausted causing the server to become unstable.

This is because for each command that is executed, 3 named pipes are created (for stdin, stdout and stderr) and they are never closed.

The fix would be to add lines to close the pipes (free the handles) to the Execute method, following the WaitForSingleObject(hProcess...). Like so:
if ( !pMsg=bNoWait )
{
WaitForSIngleObject( hProcess, INFINITE );
GetExitCodeProcess( hProcess, pReturnCode );
//
CloseHandle( si.hStdOutput );
CloseHandle( si.hStdError );
CloseHandle( si.hStdInput );
//
}

Hopefully I'll get round to creating the fixed version soon, but I wanted to publicise this in case anyone chooses to modify the source for their own purposes.
Jim

The above fixes the non-paged pool leak. However, there is also a paged memory leak, because the CreateProcess call is made without ever closing the process and thread handles. To fix this, at the end of the added section above (i.e. after the WaitForSingleObject and the named pipes have been closed) add these two lines:
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );