mirror of
https://github.com/reactos/reactos.git
synced 2025-05-07 02:41:22 +00:00
In cmd: free all memory before exiting to prevent "memory leak" messages (bug 4510). Also, CMD /? should exit with a code of 1 instead of 0.
svn path=/trunk/; revision=41808
This commit is contained in:
parent
6ddc722505
commit
24fe0f5f8c
1 changed files with 36 additions and 53 deletions
|
@ -739,42 +739,22 @@ ExecuteCommand(PARSED_COMMAND *Cmd)
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
|
||||||
GrowIfNecessary_dbg ( UINT needed, LPTSTR* ret, UINT* retlen, const char *file, int line )
|
|
||||||
{
|
|
||||||
if ( *ret && needed < *retlen )
|
|
||||||
return TRUE;
|
|
||||||
*retlen = needed;
|
|
||||||
if ( *ret )
|
|
||||||
cmd_free ( *ret );
|
|
||||||
#ifdef _DEBUG_MEM
|
|
||||||
*ret = (LPTSTR)cmd_alloc_dbg ( *retlen * sizeof(TCHAR), file, line );
|
|
||||||
#else
|
|
||||||
*ret = (LPTSTR)cmd_alloc ( *retlen * sizeof(TCHAR) );
|
|
||||||
#endif
|
|
||||||
if ( !*ret )
|
|
||||||
SetLastError ( ERROR_OUTOFMEMORY );
|
|
||||||
return *ret != NULL;
|
|
||||||
}
|
|
||||||
#define GrowIfNecessary(x, y, z) GrowIfNecessary_dbg(x, y, z, __FILE__, __LINE__)
|
|
||||||
|
|
||||||
LPTSTR
|
LPTSTR
|
||||||
GetEnvVar(LPCTSTR varName)
|
GetEnvVar(LPCTSTR varName)
|
||||||
{
|
{
|
||||||
static LPTSTR ret = NULL;
|
static LPTSTR ret = NULL;
|
||||||
static UINT retlen = 0;
|
|
||||||
UINT size;
|
UINT size;
|
||||||
|
|
||||||
size = GetEnvironmentVariable ( varName, ret, retlen );
|
cmd_free(ret);
|
||||||
if ( size > retlen )
|
ret = NULL;
|
||||||
|
size = GetEnvironmentVariable(varName, NULL, 0);
|
||||||
|
if (size > 0)
|
||||||
{
|
{
|
||||||
if ( !GrowIfNecessary ( size, &ret, &retlen ) )
|
ret = cmd_alloc(size * sizeof(TCHAR));
|
||||||
return NULL;
|
if (ret != NULL)
|
||||||
size = GetEnvironmentVariable ( varName, ret, retlen );
|
GetEnvironmentVariable(varName, ret, size + 1);
|
||||||
}
|
}
|
||||||
if ( size )
|
return ret;
|
||||||
return ret;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LPCTSTR
|
LPCTSTR
|
||||||
|
@ -1636,9 +1616,6 @@ Initialize()
|
||||||
NtReadVirtualMemoryPtr = (NtReadVirtualMemoryProc)GetProcAddress(NtDllModule, "NtReadVirtualMemory");
|
NtReadVirtualMemoryPtr = (NtReadVirtualMemoryProc)GetProcAddress(NtDllModule, "NtReadVirtualMemory");
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdLine = GetCommandLine();
|
|
||||||
TRACE ("[command args: %s]\n", debugstr_aw(cmdLine));
|
|
||||||
|
|
||||||
InitLocale ();
|
InitLocale ();
|
||||||
|
|
||||||
/* get default input and output console handles */
|
/* get default input and output console handles */
|
||||||
|
@ -1652,9 +1629,32 @@ Initialize()
|
||||||
if (GetEnvironmentVariable(_T("PROMPT"),lpBuffer, sizeof(lpBuffer) / sizeof(lpBuffer[0])) == 0)
|
if (GetEnvironmentVariable(_T("PROMPT"),lpBuffer, sizeof(lpBuffer) / sizeof(lpBuffer[0])) == 0)
|
||||||
SetEnvironmentVariable (_T("PROMPT"), _T("$P$G"));
|
SetEnvironmentVariable (_T("PROMPT"), _T("$P$G"));
|
||||||
|
|
||||||
|
#ifdef FEATURE_DIR_STACK
|
||||||
|
/* initialize directory stack */
|
||||||
|
InitDirectoryStack ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEATURE_HISTORY
|
||||||
|
/*initialize history*/
|
||||||
|
InitHistory();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Set COMSPEC environment variable */
|
||||||
|
if (0 != GetModuleFileName (NULL, ModuleName, _MAX_PATH + 1))
|
||||||
|
{
|
||||||
|
ModuleName[_MAX_PATH] = _T('\0');
|
||||||
|
SetEnvironmentVariable (_T("COMSPEC"), ModuleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add ctrl break handler */
|
||||||
|
AddBreakHandler ();
|
||||||
|
|
||||||
|
|
||||||
SetConsoleMode (hIn, ENABLE_PROCESSED_INPUT);
|
SetConsoleMode (hIn, ENABLE_PROCESSED_INPUT);
|
||||||
|
|
||||||
|
cmdLine = GetCommandLine();
|
||||||
|
TRACE ("[command args: %s]\n", debugstr_aw(cmdLine));
|
||||||
|
|
||||||
for (ptr = cmdLine; *ptr; ptr++)
|
for (ptr = cmdLine; *ptr; ptr++)
|
||||||
{
|
{
|
||||||
if (*ptr == _T('/'))
|
if (*ptr == _T('/'))
|
||||||
|
@ -1663,7 +1663,9 @@ Initialize()
|
||||||
if (option == _T('?'))
|
if (option == _T('?'))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_CMD_HELP8);
|
ConOutResPaging(TRUE,STRING_CMD_HELP8);
|
||||||
cmd_exit(0);
|
nErrorLevel = 1;
|
||||||
|
bExit = TRUE;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (option == _T('P'))
|
else if (option == _T('P'))
|
||||||
{
|
{
|
||||||
|
@ -1731,27 +1733,6 @@ Initialize()
|
||||||
ConOutPuts(_T("(C) Copyright 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team."));
|
ConOutPuts(_T("(C) Copyright 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team."));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEATURE_DIR_STACK
|
|
||||||
/* initialize directory stack */
|
|
||||||
InitDirectoryStack ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef FEATURE_HISTORY
|
|
||||||
/*initialize history*/
|
|
||||||
InitHistory();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set COMSPEC environment variable */
|
|
||||||
if (0 != GetModuleFileName (NULL, ModuleName, _MAX_PATH + 1))
|
|
||||||
{
|
|
||||||
ModuleName[_MAX_PATH] = _T('\0');
|
|
||||||
SetEnvironmentVariable (_T("COMSPEC"), ModuleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add ctrl break handler */
|
|
||||||
AddBreakHandler ();
|
|
||||||
|
|
||||||
if (AutoRun)
|
if (AutoRun)
|
||||||
{
|
{
|
||||||
ExecuteAutoRunFile(HKEY_LOCAL_MACHINE);
|
ExecuteAutoRunFile(HKEY_LOCAL_MACHINE);
|
||||||
|
@ -1796,6 +1777,8 @@ static VOID Cleanup()
|
||||||
CleanHistory();
|
CleanHistory();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* free GetEnvVar's buffer */
|
||||||
|
GetEnvVar(NULL);
|
||||||
|
|
||||||
/* remove ctrl break handler */
|
/* remove ctrl break handler */
|
||||||
RemoveBreakHandler ();
|
RemoveBreakHandler ();
|
||||||
|
|
Loading…
Reference in a new issue