fix a small bug after me, and check if it really got memmory or not.

svn path=/trunk/; revision=17627
This commit is contained in:
Magnus Olsen 2005-09-04 09:29:44 +00:00
parent 25f28a6291
commit 1cb2b6830e

View file

@ -21,8 +21,8 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
{ {
TCHAR szFullName[MAX_PATH]; TCHAR szFullName[MAX_PATH];
TCHAR first[CMDLINE_LENGTH]; TCHAR first[CMDLINE_LENGTH];
TCHAR *rest; TCHAR *rest = NULL;
TCHAR *param; TCHAR *param = NULL;
BOOL bWait = FALSE; BOOL bWait = FALSE;
BOOL bBat = FALSE; BOOL bBat = FALSE;
BOOL bCreate = FALSE; BOOL bCreate = FALSE;
@ -32,9 +32,6 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
param[0] = _T('\0');
if (_tcsncmp (Rest, _T("/?"), 2) == 0) if (_tcsncmp (Rest, _T("/?"), 2) == 0)
{ {
ConOutResPaging(TRUE,STRING_START_HELP1); ConOutResPaging(TRUE,STRING_START_HELP1);
@ -50,6 +47,22 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
} }
rest = malloc ( _tcslen(Rest) + 1 * sizeof(TCHAR)); rest = malloc ( _tcslen(Rest) + 1 * sizeof(TCHAR));
if (rest == NULL)
{
error_out_of_memory();
return 1;
}
param =malloc ( _tcslen(Rest) + 1 * sizeof(TCHAR));
if (rest == NULL)
{
free(rest);
error_out_of_memory();
return 1;
}
param[0] = _T('\0');
_tcscpy(rest,Rest); _tcscpy(rest,Rest);
@ -64,7 +77,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
{ {
if(rest[i] == _T(' ')) if(rest[i] == _T(' '))
{ {
param = malloc ( _tcslen(&rest[i]) + 1 * sizeof(TCHAR));
_tcscpy(param,&rest[i]); _tcscpy(param,&rest[i]);
rest[i] = _T('\0'); rest[i] = _T('\0');
break; break;
@ -134,6 +147,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
if (param != NULL) if (param != NULL)
free(param); free(param);
return 1; return 1;
} }
@ -148,6 +162,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
if (!SearchForExecutable (_T("CMD"), szFullCmdLine)) if (!SearchForExecutable (_T("CMD"), szFullCmdLine))
{ {
error_bad_command (); error_bad_command ();
if (rest != NULL) if (rest != NULL)
free(rest); free(rest);
@ -179,8 +194,9 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
if (bBat == FALSE) if (bBat == FALSE)
{ {
_tcscpy (szFullCmdLine, first); _tcscpy (szFullCmdLine, first);
if( param ) if( param != NULL )
{ {
_tcscat(szFullCmdLine, _T(" ") ); _tcscat(szFullCmdLine, _T(" ") );
_tcscat (szFullCmdLine, param); _tcscat (szFullCmdLine, param);
} }
@ -224,7 +240,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
ErrorMessage(GetLastError (), ErrorMessage(GetLastError (),
_T("Error executing CreateProcess()!!\n")); _T("Error executing CreateProcess()!!\n"));
} }
// }
if (rest != NULL) if (rest != NULL)
free(rest); free(rest);