- Add code to detect buffer overflows and buffer underflows on memory operations. This code is only enabled if _DEBUG is defined.

- Change all calls to malloc, realloc and free to cmd_alloc, cmd_realloc and cmd_free

svn path=/trunk/; revision=28065
This commit is contained in:
Thomas Bluemel 2007-08-01 10:17:13 +00:00
parent 9da2ad12a6
commit df91a99233
57 changed files with 335 additions and 221 deletions

View file

@ -31,7 +31,6 @@
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef FEATURE_ALIASES #ifdef FEATURE_ALIASES
@ -89,9 +88,9 @@ DeleteAlias (LPTSTR pszName)
prev->next = ptr->next; prev->next = ptr->next;
else else
lpFirst = ptr->next; lpFirst = ptr->next;
free (ptr->lpName); cmd_free (ptr->lpName);
free (ptr->lpSubst); cmd_free (ptr->lpSubst);
free (ptr); cmd_free (ptr);
return; return;
} }
prev = ptr; prev = ptr;
@ -111,14 +110,14 @@ AddAlias (LPTSTR name, LPTSTR subst)
{ {
if (!_tcsicmp (ptr->lpName, name)) if (!_tcsicmp (ptr->lpName, name))
{ {
s = (LPTSTR)malloc ((_tcslen (subst) + 1)*sizeof(TCHAR)); s = (LPTSTR)cmd_alloc ((_tcslen (subst) + 1)*sizeof(TCHAR));
if (!s) if (!s)
{ {
error_out_of_memory (); error_out_of_memory ();
return; return;
} }
free (ptr->lpSubst); cmd_free (ptr->lpSubst);
ptr->lpSubst = s; ptr->lpSubst = s;
_tcscpy (ptr->lpSubst, subst); _tcscpy (ptr->lpSubst, subst);
return; return;
@ -126,27 +125,27 @@ AddAlias (LPTSTR name, LPTSTR subst)
ptr = ptr->next; ptr = ptr->next;
} }
ptr = (LPALIAS)malloc (sizeof (ALIAS)); ptr = (LPALIAS)cmd_alloc (sizeof (ALIAS));
if (!ptr) if (!ptr)
return; return;
ptr->next = 0; ptr->next = 0;
ptr->lpName = (LPTSTR)malloc ((_tcslen (name) + 1)*sizeof(TCHAR)); ptr->lpName = (LPTSTR)cmd_alloc ((_tcslen (name) + 1)*sizeof(TCHAR));
if (!ptr->lpName) if (!ptr->lpName)
{ {
error_out_of_memory (); error_out_of_memory ();
free (ptr); cmd_free (ptr);
return; return;
} }
_tcscpy (ptr->lpName, name); _tcscpy (ptr->lpName, name);
ptr->lpSubst = (LPTSTR)malloc ((_tcslen (subst) + 1)*sizeof(TCHAR)); ptr->lpSubst = (LPTSTR)cmd_alloc ((_tcslen (subst) + 1)*sizeof(TCHAR));
if (!ptr->lpSubst) if (!ptr->lpSubst)
{ {
error_out_of_memory (); error_out_of_memory ();
free (ptr->lpName); cmd_free (ptr->lpName);
free (ptr); cmd_free (ptr);
return; return;
} }
_tcscpy (ptr->lpSubst, subst); _tcscpy (ptr->lpSubst, subst);
@ -220,14 +219,14 @@ VOID DestroyAlias (VOID)
lpLast = lpFirst; lpLast = lpFirst;
lpFirst = lpLast->next; lpFirst = lpLast->next;
free (lpLast->lpName); cmd_free (lpLast->lpName);
free (lpLast->lpSubst); cmd_free (lpLast->lpSubst);
free (lpLast); cmd_free (lpLast);
} }
free (lpFirst->lpName); cmd_free (lpFirst->lpName);
free (lpFirst->lpSubst); cmd_free (lpFirst->lpSubst);
free (lpFirst); cmd_free (lpFirst);
lpFirst = NULL; lpFirst = NULL;
lpLast = NULL; lpLast = NULL;

View file

@ -33,7 +33,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_ATTRIB #ifdef INCLUDE_CMD_ATTRIB

View file

@ -39,7 +39,7 @@
* Implementation of FOR command * Implementation of FOR command
* *
* 20-Jul-1998 (John P Price <linux-guru@gcfl.net>) * 20-Jul-1998 (John P Price <linux-guru@gcfl.net>)
* added error checking after malloc calls * added error checking after cmd_alloc calls
* *
* 27-Jul-1998 (John P Price <linux-guru@gcfl.net>) * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
* added config.h include * added config.h include
@ -59,7 +59,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* The stack of current batch contexts. /* The stack of current batch contexts.
@ -114,7 +113,7 @@ LPTSTR FindArg (INT n)
LPTSTR BatchParams (LPTSTR s1, LPTSTR s2) LPTSTR BatchParams (LPTSTR s1, LPTSTR s2)
{ {
LPTSTR dp = (LPTSTR)malloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR)); LPTSTR dp = (LPTSTR)cmd_alloc ((_tcslen(s1) + _tcslen(s2) + 3) * sizeof (TCHAR));
/* JPP 20-Jul-1998 added error checking */ /* JPP 20-Jul-1998 added error checking */
if (dp == NULL) if (dp == NULL)
@ -188,19 +187,19 @@ VOID ExitBatch (LPTSTR msg)
} }
if (bc->params) if (bc->params)
free(bc->params); cmd_free(bc->params);
if (bc->forproto) if (bc->forproto)
free(bc->forproto); cmd_free(bc->forproto);
if (bc->ffind) if (bc->ffind)
free(bc->ffind); cmd_free(bc->ffind);
/* Preserve echo state across batch calls */ /* Preserve echo state across batch calls */
bEcho = bc->bEcho; bEcho = bc->bEcho;
bc = bc->prev; bc = bc->prev;
free(t); cmd_free(t);
} }
if (msg && *msg) if (msg && *msg)
@ -241,7 +240,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
if (bc == NULL) if (bc == NULL)
{ {
/* No curent batch file, create a new context */ /* No curent batch file, create a new context */
LPBATCH_CONTEXT n = (LPBATCH_CONTEXT)malloc (sizeof(BATCH_CONTEXT)); LPBATCH_CONTEXT n = (LPBATCH_CONTEXT)cmd_alloc (sizeof(BATCH_CONTEXT));
if (n == NULL) if (n == NULL)
{ {
@ -260,7 +259,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
/* Then we are transferring to another batch */ /* Then we are transferring to another batch */
CloseHandle (bc->hBatchFile); CloseHandle (bc->hBatchFile);
bc->hBatchFile = INVALID_HANDLE_VALUE; bc->hBatchFile = INVALID_HANDLE_VALUE;
free (bc->params); cmd_free (bc->params);
} }
bc->hBatchFile = hFile; bc->hBatchFile = hFile;
@ -275,7 +274,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
// //
// Allocate enough memory to hold the params and copy them over without modifications // Allocate enough memory to hold the params and copy them over without modifications
// //
bc->raw_params = (TCHAR*) malloc((_tcslen(param)+1) * sizeof(TCHAR)); bc->raw_params = (TCHAR*) cmd_alloc((_tcslen(param)+1) * sizeof(TCHAR));
if (bc->raw_params != NULL) if (bc->raw_params != NULL)
{ {
memset (bc->raw_params, 0, _tcslen(bc->raw_params) * sizeof(TCHAR)); memset (bc->raw_params, 0, _tcslen(bc->raw_params) * sizeof(TCHAR));
@ -378,7 +377,7 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
else else
{ {
/* For first find, allocate a find first block */ /* For first find, allocate a find first block */
if ((bc->ffind = (LPWIN32_FIND_DATA)malloc (sizeof (WIN32_FIND_DATA))) == NULL) if ((bc->ffind = (LPWIN32_FIND_DATA)cmd_alloc (sizeof (WIN32_FIND_DATA))) == NULL)
{ {
error_out_of_memory(); error_out_of_memory();
return NULL; return NULL;
@ -392,7 +391,7 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
if (fv == NULL) if (fv == NULL)
{ {
/* Null indicates no more files.. */ /* Null indicates no more files.. */
free (bc->ffind); /* free the buffer */ cmd_free (bc->ffind); /* free the buffer */
bc->ffind = NULL; bc->ffind = NULL;
bc->shiftlevel++; /* On to next list element */ bc->shiftlevel++; /* On to next list element */
continue; continue;

View file

@ -25,7 +25,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_BEEP #ifdef INCLUDE_CMD_BEEP

View file

@ -29,7 +29,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* /*
@ -56,7 +55,7 @@ INT cmd_call (LPTSTR cmd, LPTSTR param)
nErrorLevel = 0; nErrorLevel = 0;
n = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT)); n = (LPBATCH_CONTEXT)cmd_alloc (sizeof (BATCH_CONTEXT));
if (n == NULL) if (n == NULL)
{ {
@ -91,7 +90,7 @@ INT cmd_call (LPTSTR cmd, LPTSTR param)
if (bc->hBatchFile == INVALID_HANDLE_VALUE) if (bc->hBatchFile == INVALID_HANDLE_VALUE)
{ {
bc = bc->prev; bc = bc->prev;
free (n); cmd_free (n);
} }
return 0; return 0;

View file

@ -12,7 +12,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"

View file

@ -20,7 +20,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_CHOICE #ifdef INCLUDE_CMD_CHOICE

View file

@ -27,7 +27,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_CLS #ifdef INCLUDE_CMD_CLS

View file

@ -142,8 +142,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include <malloc.h>
#include "resource.h"
#ifndef NT_SUCCESS #ifndef NT_SUCCESS
#define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0) #define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0)
@ -351,10 +349,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest)
#endif #endif
/* we need biger buffer that First, Rest, Full are already /* we need biger buffer that First, Rest, Full are already
need rewrite some code to use realloc when it need instead need rewrite some code to use cmd_realloc when it need instead
of add 512bytes extra */ of add 512bytes extra */
first = malloc ( (_tcslen(First) + 512) * sizeof(TCHAR)); first = cmd_alloc ( (_tcslen(First) + 512) * sizeof(TCHAR));
if (first == NULL) if (first == NULL)
{ {
error_out_of_memory(); error_out_of_memory();
@ -362,31 +360,31 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest)
return ; return ;
} }
rest = malloc ( (_tcslen(Rest) + 512) * sizeof(TCHAR)); rest = cmd_alloc ( (_tcslen(Rest) + 512) * sizeof(TCHAR));
if (rest == NULL) if (rest == NULL)
{ {
free (first); cmd_free (first);
error_out_of_memory(); error_out_of_memory();
nErrorLevel = 1; nErrorLevel = 1;
return ; return ;
} }
full = malloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); full = cmd_alloc ( (_tcslen(Full) + 512) * sizeof(TCHAR));
if (full == NULL) if (full == NULL)
{ {
free (first); cmd_free (first);
free (rest); cmd_free (rest);
error_out_of_memory(); error_out_of_memory();
nErrorLevel = 1; nErrorLevel = 1;
return ; return ;
} }
szFullName = malloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); szFullName = cmd_alloc ( (_tcslen(Full) + 512) * sizeof(TCHAR));
if (full == NULL) if (full == NULL)
{ {
free (first); cmd_free (first);
free (rest); cmd_free (rest);
free (full); cmd_free (full);
error_out_of_memory(); error_out_of_memory();
nErrorLevel = 1; nErrorLevel = 1;
return ; return ;
@ -455,10 +453,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest)
if (!working) ConErrResPuts (STRING_FREE_ERROR1); if (!working) ConErrResPuts (STRING_FREE_ERROR1);
free (first); cmd_free (first);
free (rest); cmd_free (rest);
free (full); cmd_free (full);
free (szFullName); cmd_free (szFullName);
nErrorLevel = 1; nErrorLevel = 1;
return; return;
} }
@ -468,10 +466,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest)
if (!SearchForExecutable (first, szFullName)) if (!SearchForExecutable (first, szFullName))
{ {
error_bad_command (); error_bad_command ();
free (first); cmd_free (first);
free (rest); cmd_free (rest);
free (full); cmd_free (full);
free (szFullName); cmd_free (szFullName);
nErrorLevel = 1; nErrorLevel = 1;
return; return;
@ -572,10 +570,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest)
OutputCodePage = GetConsoleOutputCP(); OutputCodePage = GetConsoleOutputCP();
SetConsoleTitle (szWindowTitle); SetConsoleTitle (szWindowTitle);
free(first); cmd_free(first);
free(rest); cmd_free(rest);
free(full); cmd_free(full);
free (szFullName); cmd_free (szFullName);
} }
@ -602,7 +600,7 @@ DoCommand (LPTSTR line)
DebugPrintf (_T("DoCommand: (\'%s\')\n"), line); DebugPrintf (_T("DoCommand: (\'%s\')\n"), line);
#endif /* DEBUG */ #endif /* DEBUG */
com = malloc( (_tcslen(line) +512)*sizeof(TCHAR) ); com = cmd_alloc( (_tcslen(line) +512)*sizeof(TCHAR) );
if (com == NULL) if (com == NULL)
{ {
error_out_of_memory(); error_out_of_memory();
@ -646,7 +644,7 @@ DoCommand (LPTSTR line)
if(_tcslen(com) > MAX_PATH) if(_tcslen(com) > MAX_PATH)
{ {
error_bad_command(); error_bad_command();
free(com); cmd_free(com);
return; return;
} }
*/ */
@ -700,7 +698,7 @@ DoCommand (LPTSTR line)
} }
} }
} }
free(com); cmd_free(com);
} }
@ -1124,8 +1122,8 @@ GrowIfNecessary ( UINT needed, LPTSTR* ret, UINT* retlen )
return TRUE; return TRUE;
*retlen = needed; *retlen = needed;
if ( *ret ) if ( *ret )
free ( *ret ); cmd_free ( *ret );
*ret = (LPTSTR)malloc ( *retlen * sizeof(TCHAR) ); *ret = (LPTSTR)cmd_alloc ( *retlen * sizeof(TCHAR) );
if ( !*ret ) if ( !*ret )
SetLastError ( ERROR_OUTOFMEMORY ); SetLastError ( ERROR_OUTOFMEMORY );
return *ret != NULL; return *ret != NULL;

View file

@ -31,6 +31,8 @@
#include "cmdver.h" #include "cmdver.h"
#include "cmddbg.h"
#define BREAK_BATCHFILE 1 #define BREAK_BATCHFILE 1
#define BREAK_OUTOFBATCH 2 #define BREAK_OUTOFBATCH 2
#define BREAK_INPUT 3 #define BREAK_INPUT 3

View file

@ -17,6 +17,7 @@
<file>choice.c</file> <file>choice.c</file>
<file>cls.c</file> <file>cls.c</file>
<file>cmd.c</file> <file>cmd.c</file>
<file>cmddbg.c</file>
<file>cmdinput.c</file> <file>cmdinput.c</file>
<file>cmdtable.c</file> <file>cmdtable.c</file>
<file>color.c</file> <file>color.c</file>

View file

@ -0,0 +1,140 @@
#include <precomp.h>
#ifdef _DEBUG
#define REDZONE_SIZE 32
#define REDZONE_LEFT 0x78
#define REDZONE_RIGHT 0x87
typedef struct
{
size_t size;
const char *file;
int line;
} alloc_info, *palloc_info;
static void *
get_base_ptr(void *ptr)
{
return (void *)((UINT_PTR)ptr - REDZONE_SIZE - sizeof(alloc_info));
}
static void *
write_redzone(void *ptr, size_t size, const char *file, int line)
{
void *ret;
palloc_info info = (palloc_info)ptr;
info->size = size;
info->file = file;
info->line = line;
ptr = (void *)(info + 1);
memset(ptr, REDZONE_LEFT, REDZONE_SIZE);
ret = (void *)((size_t)ptr + REDZONE_SIZE);
ptr = (void *)((size_t)ret + size);
memset(ptr, REDZONE_RIGHT, REDZONE_SIZE);
return ret;
}
static int
check_redzone_region(void *ptr, unsigned char sig, void **newptr)
{
unsigned char *p, *q;
int ret = 1;
p = (unsigned char *)ptr;
q = p + REDZONE_SIZE;
while (p != q)
{
if (*(p++) != sig)
ret = 0;
}
if (newptr != NULL)
*newptr = p;
return ret;
}
static void
redzone_err(const char *msg, palloc_info info, void *ptr, const char *file, int line)
{
DbgPrint("CMD: %s\n", msg);
DbgPrint(" Block: 0x%p Size: %lu\n", ptr, info->size);
DbgPrint(" Allocated from %s:%d\n", info->file, info->line);
DbgPrint(" Called from: %s:%d\n", file, line);
ExitProcess(1);
}
static void
check_redzone(void *ptr, const char *file, int line)
{
palloc_info info = (palloc_info)ptr;
ptr = (void *)(info + 1);
if (!check_redzone_region(ptr, REDZONE_LEFT, &ptr))
redzone_err("Detected buffer underflow!", info, ptr, file, line);
ptr = (void *)((UINT_PTR)ptr + info->size);
if (!check_redzone_region(ptr, REDZONE_RIGHT, NULL))
redzone_err("Detected buffer overflow!", info, ptr, file, line);
}
static size_t
calculate_size_with_redzone(size_t size)
{
return sizeof(alloc_info) + size + (2 * REDZONE_SIZE);
}
void *
cmd_alloc_dbg(size_t size, const char *file, int line)
{
void *newptr = NULL;
newptr = malloc(calculate_size_with_redzone(size));
if (newptr != NULL)
newptr = write_redzone(newptr, size, file, line);
return newptr;
}
void *
cmd_realloc_dbg(void *ptr, size_t size, const char *file, int line)
{
void *newptr = NULL;
if (ptr == NULL)
return cmd_alloc_dbg(size, file, line);
if (size == 0)
{
cmd_free_dbg(ptr, file, line);
return NULL;
}
ptr = get_base_ptr(ptr);
check_redzone(ptr, file, line);
newptr = realloc(ptr, calculate_size_with_redzone(size));
if (newptr != NULL)
newptr = write_redzone(newptr, size, file, line);
return newptr;
}
void
cmd_free_dbg(void *ptr, const char *file, int line)
{
if (ptr != NULL)
{
ptr = get_base_ptr(ptr);
check_redzone(ptr, file, line);
}
free(ptr);
}
void
cmd_exit(int code)
{
ExitProcess(code);
}
#endif /* _DEBUG */

View file

@ -0,0 +1,22 @@
#ifdef _DEBUG
#define cmd_alloc(size) cmd_alloc_dbg(size, __FILE__, __LINE__)
#define cmd_realloc(ptr,size) cmd_realloc_dbg(ptr, size, __FILE__, __LINE__)
#define cmd_free(ptr) cmd_free_dbg(ptr, __FILE__, __LINE__)
void *
cmd_alloc_dbg(size_t size, const char *file, int line);
void *
cmd_realloc_dbg(void *ptr, size_t size, const char *file, int line);
void
cmd_free_dbg(void *ptr, const char *file, int line);
#else
#define cmd_alloc(size) malloc(size)
#define cmd_realloc(ptr,size) realloc(ptr, size)
#define cmd_free(ptr) free(ptr)
#endif

View file

@ -98,7 +98,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
SHORT maxx; SHORT maxx;

View file

@ -18,7 +18,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* a list of all the internal commands, associating their command names */ /* a list of all the internal commands, associating their command names */

View file

@ -21,7 +21,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_COLOR #ifdef INCLUDE_CMD_COLOR

View file

@ -17,10 +17,7 @@
* Fixed ConPrintfPaging * Fixed ConPrintfPaging
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#define OUTPUT_BUFFER_SIZE 4096 #define OUTPUT_BUFFER_SIZE 4096
@ -103,7 +100,7 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength)
PCHAR pBuf; PCHAR pBuf;
#ifdef _UNICODE #ifdef _UNICODE
pBuf = (PCHAR)malloc(dwLength); pBuf = (PCHAR)cmd_alloc(dwLength);
#else #else
pBuf = lpInput; pBuf = lpInput;
#endif #endif
@ -129,7 +126,7 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength)
} }
#ifdef _UNICODE #ifdef _UNICODE
free(pBuf); cmd_free(pBuf);
#endif #endif
SetConsoleMode (hFile, dwOldMode); SetConsoleMode (hFile, dwOldMode);
@ -169,7 +166,7 @@ VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
len = _tcslen(szText); len = _tcslen(szText);
#ifdef _UNICODE #ifdef _UNICODE
pBuf = malloc(len + 1); pBuf = cmd_alloc(len + 1);
len = WideCharToMultiByte( OutputCodePage, 0, szText, len + 1, pBuf, len + 1, NULL, NULL) - 1; len = WideCharToMultiByte( OutputCodePage, 0, szText, len + 1, pBuf, len + 1, NULL, NULL) - 1;
#else #else
pBuf = szText; pBuf = szText;
@ -185,7 +182,7 @@ VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
&dwWritten, &dwWritten,
NULL); NULL);
#ifdef _UNICODE #ifdef _UNICODE
free(pBuf); cmd_free(pBuf);
#endif #endif
} }
@ -219,7 +216,7 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
len = _vstprintf (szOut, szFormat, arg_ptr); len = _vstprintf (szOut, szFormat, arg_ptr);
#ifdef _UNICODE #ifdef _UNICODE
pBuf = malloc(len + 1); pBuf = cmd_alloc(len + 1);
len = WideCharToMultiByte( OutputCodePage, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1; len = WideCharToMultiByte( OutputCodePage, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1;
#else #else
pBuf = szOut; pBuf = szOut;
@ -233,7 +230,7 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
#ifdef _UNICODE #ifdef _UNICODE
free(pBuf); cmd_free(pBuf);
#endif #endif
} }
@ -287,7 +284,7 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa
len = _vstprintf (szOut, szFormat, arg_ptr); len = _vstprintf (szOut, szFormat, arg_ptr);
#ifdef _UNICODE #ifdef _UNICODE
pBuf = malloc(len + 1); pBuf = cmd_alloc(len + 1);
len = WideCharToMultiByte( OutputCodePage, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1; len = WideCharToMultiByte( OutputCodePage, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1;
#else #else
pBuf = szOut; pBuf = szOut;
@ -311,7 +308,7 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa
if(PagePrompt() != PROMPT_YES) if(PagePrompt() != PROMPT_YES)
{ {
#ifdef _UNICODE #ifdef _UNICODE
free(pBuf); cmd_free(pBuf);
#endif #endif
return 1; return 1;
} }
@ -323,7 +320,7 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa
} }
#ifdef _UNICODE #ifdef _UNICODE
free(pBuf); cmd_free(pBuf);
#endif #endif
return 0; return 0;
} }

View file

@ -32,7 +32,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_COPY #ifdef INCLUDE_CMD_COPY
@ -264,7 +263,7 @@ copy (TCHAR source[MAX_PATH],
{ {
ConOutResPuts(STRING_COPY_ERROR3); ConOutResPuts(STRING_COPY_ERROR3);
free (buffer); cmd_free (buffer);
CloseHandle (hFileDest); CloseHandle (hFileDest);
CloseHandle (hFileSrc); CloseHandle (hFileSrc);
nErrorLevel = 1; nErrorLevel = 1;
@ -375,7 +374,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param)
nErrorLevel = 0; nErrorLevel = 0;
/* Get the envor value if it exists */ /* Get the envor value if it exists */
evar = malloc(512 * sizeof(TCHAR)); evar = cmd_alloc(512 * sizeof(TCHAR));
if (evar==NULL) size = 0; if (evar==NULL) size = 0;
else else
{ {
@ -383,7 +382,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param)
} }
if (size > 512) if (size > 512)
{ {
evar = realloc(evar,size * sizeof(TCHAR) ); evar = cmd_realloc(evar,size * sizeof(TCHAR) );
if (evar!=NULL) if (evar!=NULL)
{ {
size = GetEnvironmentVariable (_T("COPYCMD"), evar, size); size = GetEnvironmentVariable (_T("COPYCMD"), evar, size);
@ -449,7 +448,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param)
} }
} }
} }
free(evar); cmd_free(evar);
/*Split the user input into array*/ /*Split the user input into array*/
@ -873,7 +872,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param)
FindClose(hFile); FindClose(hFile);
if (arg!=NULL) if (arg!=NULL)
free(arg); cmd_free(arg);
return 0; return 0;
} }

View file

@ -32,7 +32,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_DATE #ifdef INCLUDE_CMD_DATE

View file

@ -46,7 +46,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_DEL #ifdef INCLUDE_CMD_DEL

View file

@ -10,7 +10,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_DELAY #ifdef INCLUDE_CMD_DELAY

View file

@ -135,7 +135,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_DIR #ifdef INCLUDE_CMD_DIR
@ -365,19 +364,19 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */
cCurSwitch = _T(' '); cCurSwitch = _T(' ');
if(ptrStart && ptrEnd) if(ptrStart && ptrEnd)
{ {
temp = malloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); temp = cmd_alloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR));
if(!temp) if(!temp)
return FALSE; return FALSE;
memcpy(temp, ptrStart, (ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); memcpy(temp, ptrStart, (ptrEnd - ptrStart) + 2 * sizeof (TCHAR));
temp[(ptrEnd - ptrStart + 1)] = _T('\0'); temp[(ptrEnd - ptrStart + 1)] = _T('\0');
if(!add_entry(entries, params, temp)) if(!add_entry(entries, params, temp))
{ {
free(temp); cmd_free(temp);
freep(*params); freep(*params);
return FALSE; return FALSE;
} }
free(temp); cmd_free(temp);
ptrStart = NULL; ptrStart = NULL;
ptrEnd = NULL; ptrEnd = NULL;
@ -397,19 +396,19 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */
/* Process a character for parameter */ /* Process a character for parameter */
if ((cCurSwitch == _T(' ')) && ptrStart && ptrEnd) if ((cCurSwitch == _T(' ')) && ptrStart && ptrEnd)
{ {
temp = malloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); temp = cmd_alloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR));
if(!temp) if(!temp)
return FALSE; return FALSE;
memcpy(temp, ptrStart, (ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); memcpy(temp, ptrStart, (ptrEnd - ptrStart) + 2 * sizeof (TCHAR));
temp[(ptrEnd - ptrStart + 1)] = _T('\0'); temp[(ptrEnd - ptrStart + 1)] = _T('\0');
if(!add_entry(entries, params, temp)) if(!add_entry(entries, params, temp))
{ {
free(temp); cmd_free(temp);
freep(*params); freep(*params);
return FALSE; return FALSE;
} }
free(temp); cmd_free(temp);
ptrStart = NULL; ptrStart = NULL;
ptrEnd = NULL; ptrEnd = NULL;
@ -568,19 +567,19 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */
/* Terminate the parameters */ /* Terminate the parameters */
if(ptrStart && ptrEnd) if(ptrStart && ptrEnd)
{ {
temp = malloc((ptrEnd - ptrStart + 2) * sizeof(TCHAR)); temp = cmd_alloc((ptrEnd - ptrStart + 2) * sizeof(TCHAR));
if(!temp) if(!temp)
return FALSE; return FALSE;
memcpy(temp, ptrStart, (ptrEnd - ptrStart + 1) * sizeof(TCHAR)); memcpy(temp, ptrStart, (ptrEnd - ptrStart + 1) * sizeof(TCHAR));
temp[(ptrEnd - ptrStart + 1)] = _T('\0'); temp[(ptrEnd - ptrStart + 1)] = _T('\0');
if(!add_entry(entries, params, temp)) if(!add_entry(entries, params, temp))
{ {
free(temp); cmd_free(temp);
freep(*params); freep(*params);
return FALSE; return FALSE;
} }
free(temp); cmd_free(temp);
ptrStart = NULL; ptrStart = NULL;
ptrEnd = NULL; ptrEnd = NULL;
@ -1770,7 +1769,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
_tcscat (szFullFileSpec, szFilespec); _tcscat (szFullFileSpec, szFilespec);
/* Prepare the linked list, first node is allocated */ /* Prepare the linked list, first node is allocated */
ptrStartNode = malloc(sizeof(DIRFINDLISTNODE)); ptrStartNode = cmd_alloc(sizeof(DIRFINDLISTNODE));
if (ptrStartNode == NULL) if (ptrStartNode == NULL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -1790,7 +1789,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
if ((wfdFileInfo.dwFileAttributes & lpFlags->stAttribs.dwAttribMask ) if ((wfdFileInfo.dwFileAttributes & lpFlags->stAttribs.dwAttribMask )
== (lpFlags->stAttribs.dwAttribMask & lpFlags->stAttribs.dwAttribVal )) == (lpFlags->stAttribs.dwAttribMask & lpFlags->stAttribs.dwAttribVal ))
{ {
ptrNextNode->ptrNext = malloc(sizeof(DIRFINDLISTNODE)); ptrNextNode->ptrNext = cmd_alloc(sizeof(DIRFINDLISTNODE));
if (ptrNextNode->ptrNext == NULL) if (ptrNextNode->ptrNext == NULL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -1799,14 +1798,14 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
while (ptrStartNode) while (ptrStartNode)
{ {
ptrNextNode = ptrStartNode->ptrNext; ptrNextNode = ptrStartNode->ptrNext;
free(ptrStartNode); cmd_free(ptrStartNode);
ptrStartNode = ptrNextNode; ptrStartNode = ptrNextNode;
dwCount --; dwCount --;
} }
return 1; return 1;
} }
/* If malloc fails we go to next file in hope it works, /* If cmd_alloc fails we go to next file in hope it works,
without braking the linked list! */ without braking the linked list! */
if (ptrNextNode->ptrNext) if (ptrNextNode->ptrNext)
{ {
@ -1850,7 +1849,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
ptrNextNode->ptrNext = NULL; ptrNextNode->ptrNext = NULL;
/* Calculate and allocate space need for making an array of pointers */ /* Calculate and allocate space need for making an array of pointers */
ptrFileArray = malloc(sizeof(LPWIN32_FIND_DATA) * dwCount); ptrFileArray = cmd_alloc(sizeof(LPWIN32_FIND_DATA) * dwCount);
if (ptrFileArray == NULL) if (ptrFileArray == NULL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -1859,7 +1858,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
while (ptrStartNode) while (ptrStartNode)
{ {
ptrNextNode = ptrStartNode->ptrNext; ptrNextNode = ptrStartNode->ptrNext;
free(ptrStartNode); cmd_free(ptrStartNode);
ptrStartNode = ptrNextNode; ptrStartNode = ptrNextNode;
dwCount --; dwCount --;
} }
@ -1887,7 +1886,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
DirPrintFiles(ptrFileArray, dwCount, szFullPath, lpFlags); DirPrintFiles(ptrFileArray, dwCount, szFullPath, lpFlags);
/* Free array */ /* Free array */
free(ptrFileArray); cmd_free(ptrFileArray);
if (CheckCtrlBreak(BREAK_INPUT)) if (CheckCtrlBreak(BREAK_INPUT))
return 1; return 1;
@ -1933,7 +1932,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
while (ptrStartNode) while (ptrStartNode)
{ {
ptrNextNode = ptrStartNode->ptrNext; ptrNextNode = ptrStartNode->ptrNext;
free(ptrStartNode); cmd_free(ptrStartNode);
ptrStartNode = ptrNextNode; ptrStartNode = ptrNextNode;
dwCount --; dwCount --;
} }

View file

@ -15,7 +15,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef FEATURE_DIRECTORY_STACK #ifdef FEATURE_DIRECTORY_STACK
@ -39,7 +38,7 @@ PushDirectory (LPTSTR pszPath)
nErrorLevel = 0; nErrorLevel = 0;
lpDir = (LPDIRENTRY)malloc (sizeof (DIRENTRY)); lpDir = (LPDIRENTRY)cmd_alloc (sizeof (DIRENTRY));
if (!lpDir) if (!lpDir)
{ {
error_out_of_memory (); error_out_of_memory ();
@ -59,10 +58,10 @@ PushDirectory (LPTSTR pszPath)
} }
lpStackTop = lpDir; lpStackTop = lpDir;
lpDir->pszPath = (LPTSTR)malloc ((_tcslen(pszPath)+1)*sizeof(TCHAR)); lpDir->pszPath = (LPTSTR)cmd_alloc ((_tcslen(pszPath)+1)*sizeof(TCHAR));
if (!lpDir->pszPath) if (!lpDir->pszPath)
{ {
free (lpDir); cmd_free (lpDir);
error_out_of_memory (); error_out_of_memory ();
return -1; return -1;
} }
@ -92,8 +91,8 @@ PopDirectory (VOID)
else else
lpStackBottom = NULL; lpStackBottom = NULL;
free (lpDir->pszPath); cmd_free (lpDir->pszPath);
free (lpDir); cmd_free (lpDir);
nStackDepth--; nStackDepth--;
} }

View file

@ -27,7 +27,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
INT CommandEcho (LPTSTR cmd, LPTSTR param) INT CommandEcho (LPTSTR cmd, LPTSTR param)

View file

@ -21,7 +21,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...) VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...)

View file

@ -21,7 +21,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "cmd.h"
#ifdef FEATURE_UNIX_FILENAME_COMPLETION #ifdef FEATURE_UNIX_FILENAME_COMPLETION
@ -490,8 +489,8 @@ VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix)
FileName * File2; FileName * File2;
INT ret; INT ret;
File1 = malloc(sizeof(FileName)); File1 = cmd_alloc(sizeof(FileName));
File2 = malloc(sizeof(FileName)); File2 = cmd_alloc(sizeof(FileName));
if(!File1 || !File2) if(!File1 || !File2)
return 0; return 0;
@ -501,8 +500,8 @@ VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix)
/* ret = _tcsicmp(File1->Name, File2->Name); */ /* ret = _tcsicmp(File1->Name, File2->Name); */
ret = lstrcmpi(File1->Name, File2->Name); ret = lstrcmpi(File1->Name, File2->Name);
free(File1); cmd_free(File1);
free(File2); cmd_free(File2);
return ret; return ret;
} }
@ -628,7 +627,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
} }
/* Add the file to the list of files */ /* Add the file to the list of files */
FileList = realloc(FileList, ++FileListSize * sizeof(FileName)); FileList = cmd_realloc(FileList, ++FileListSize * sizeof(FileName));
if(FileList == NULL) if(FileList == NULL)
{ {
@ -651,7 +650,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
{ {
_tcscpy(strOut,szOrginal); _tcscpy(strOut,szOrginal);
if(FileList != NULL) if(FileList != NULL)
free(FileList); cmd_free(FileList);
return; return;
} }
@ -741,7 +740,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
EndLength = _tcslen(strOut); EndLength = _tcslen(strOut);
DiffLength = EndLength - StartLength; DiffLength = EndLength - StartLength;
if(FileList != NULL) if(FileList != NULL)
free(FileList); cmd_free(FileList);
} }
#endif #endif

View file

@ -31,7 +31,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* /*
@ -126,7 +125,7 @@ INT cmd_for (LPTSTR cmd, LPTSTR param)
} }
/* OK all is correct, build a bcontext.... */ /* OK all is correct, build a bcontext.... */
lpNew = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT)); lpNew = (LPBATCH_CONTEXT)cmd_alloc (sizeof (BATCH_CONTEXT));
lpNew->prev = bc; lpNew->prev = bc;
bc = lpNew; bc = lpNew;

View file

@ -12,7 +12,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_FREE #ifdef INCLUDE_CMD_FREE

View file

@ -27,7 +27,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* /*

View file

@ -139,8 +139,8 @@ VOID InitHistory(VOID)
{ {
size=0; size=0;
Top = malloc(sizeof(HIST_ENTRY)); Top = cmd_alloc(sizeof(HIST_ENTRY));
Bottom = malloc(sizeof(HIST_ENTRY)); Bottom = cmd_alloc(sizeof(HIST_ENTRY));
Top->prev = Bottom; Top->prev = Bottom;
Top->next = NULL; Top->next = NULL;
@ -161,8 +161,8 @@ VOID CleanHistory(VOID)
while (Bottom->next!=Top) while (Bottom->next!=Top)
del(Bottom->next); del(Bottom->next);
free(Top); cmd_free(Top);
free(Bottom); cmd_free(Bottom);
} }
@ -204,13 +204,13 @@ VOID del(LPHIST_ENTRY item)
/*free string's mem*/ /*free string's mem*/
if (item->string) if (item->string)
free(item->string); cmd_free(item->string);
/*set links in prev and next item*/ /*set links in prev and next item*/
item->next->prev=item->prev; item->next->prev=item->prev;
item->prev->next=item->next; item->prev->next=item->next;
free(item); cmd_free(item);
size--; size--;
} }
@ -233,8 +233,8 @@ VOID add_before_last(LPTSTR string)
return; return;
/*allocte entry and string*/ /*allocte entry and string*/
tmp=malloc(sizeof(HIST_ENTRY)); tmp=cmd_alloc(sizeof(HIST_ENTRY));
tmp->string=malloc((_tcslen(string)+1)*sizeof(TCHAR)); tmp->string=cmd_alloc((_tcslen(string)+1)*sizeof(TCHAR));
_tcscpy(tmp->string,string); _tcscpy(tmp->string,string);
/*set links*/ /*set links*/
@ -280,7 +280,7 @@ VOID add_at_bottom(LPTSTR string)
/*fill bottom with string, it will become Bottom->next*/ /*fill bottom with string, it will become Bottom->next*/
Bottom->string=malloc((_tcslen(string)+1)*sizeof(TCHAR)); Bottom->string=cmd_alloc((_tcslen(string)+1)*sizeof(TCHAR));
_tcscpy(Bottom->string,string); _tcscpy(Bottom->string,string);
/*save Bottom value*/ /*save Bottom value*/
@ -288,7 +288,7 @@ VOID add_at_bottom(LPTSTR string)
/*create new void Bottom*/ /*create new void Bottom*/
Bottom=malloc(sizeof(HIST_ENTRY)); Bottom=cmd_alloc(sizeof(HIST_ENTRY));
Bottom->next=tmp; Bottom->next=tmp;
Bottom->prev=NULL; Bottom->prev=NULL;
Bottom->string=NULL; Bottom->string=NULL;
@ -401,7 +401,7 @@ VOID History (INT dir, LPTSTR commandline)
/*first time History is called allocate mem*/ /*first time History is called allocate mem*/
if (!history) if (!history)
{ {
history = malloc (history_size * sizeof (TCHAR)); history = cmd_alloc (history_size * sizeof (TCHAR));
lines[0] = history; lines[0] = history;
history[0] = 0; history[0] = 0;
} }

View file

@ -31,7 +31,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#define X_EXEC 1 #define X_EXEC 1

View file

@ -138,7 +138,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_CHDIR #ifdef INCLUDE_CMD_CHDIR
@ -154,7 +153,7 @@ VOID InitLastPath (VOID)
VOID FreeLastPath (VOID) VOID FreeLastPath (VOID)
{ {
if (lpLastPath) if (lpLastPath)
free (lpLastPath); cmd_free (lpLastPath);
} }
/* help functions for getting current path from drive /* help functions for getting current path from drive
@ -766,11 +765,11 @@ INT CommandShowCommandsDetail (LPTSTR cmd, LPTSTR param)
/* If a param was send, display help of correspondent command */ /* If a param was send, display help of correspondent command */
if (_tcslen(param)) if (_tcslen(param))
{ {
LPTSTR NewCommand = malloc((_tcslen(param)+4)*sizeof(TCHAR)); LPTSTR NewCommand = cmd_alloc((_tcslen(param)+4)*sizeof(TCHAR));
_tcscpy(NewCommand, param); _tcscpy(NewCommand, param);
_tcscat(NewCommand, _T(" /?")); _tcscat(NewCommand, _T(" /?"));
DoCommand(NewCommand); DoCommand(NewCommand);
free(NewCommand); cmd_free(NewCommand);
} }
/* Else, display detailed commands list */ /* Else, display detailed commands list */
else else

View file

@ -18,7 +18,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_LABEL #ifdef INCLUDE_CMD_LABEL

View file

@ -12,7 +12,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
TCHAR cDateSeparator; TCHAR cDateSeparator;

View file

@ -1,5 +1,4 @@
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef _UNICODE #ifdef _UNICODE
extern int _main (void); extern int _main (void);

View file

@ -12,7 +12,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_MEMORY #ifdef INCLUDE_CMD_MEMORY

View file

@ -33,7 +33,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* /*
@ -200,7 +199,7 @@ BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry)
LPTSTR q; LPTSTR q;
LPTSTR *oldarg; LPTSTR *oldarg;
q = malloc ((_tcslen(entry) + 1) * sizeof (TCHAR)); q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
if (NULL == q) if (NULL == q)
{ {
return FALSE; return FALSE;
@ -208,7 +207,7 @@ BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry)
_tcscpy (q, entry); _tcscpy (q, entry);
oldarg = *arg; oldarg = *arg;
*arg = realloc (oldarg, (*ac + 2) * sizeof (LPTSTR)); *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
if (NULL == *arg) if (NULL == *arg)
{ {
*arg = oldarg; *arg = oldarg;
@ -233,7 +232,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
pathend = _tcsrchr (pattern, _T('\\')); pathend = _tcsrchr (pattern, _T('\\'));
if (NULL != pathend) if (NULL != pathend)
{ {
dirpart = malloc((pathend - pattern + 2) * sizeof(TCHAR)); dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
if (NULL == dirpart) if (NULL == dirpart)
{ {
return FALSE; return FALSE;
@ -252,7 +251,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
{ {
if (NULL != dirpart) if (NULL != dirpart)
{ {
fullname = malloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR)); fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
if (NULL == fullname) if (NULL == fullname)
{ {
ok = FALSE; ok = FALSE;
@ -261,7 +260,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
{ {
_tcscat (_tcscpy (fullname, dirpart), FindData.cFileName); _tcscat (_tcscpy (fullname, dirpart), FindData.cFileName);
ok = add_entry(ac, arg, fullname); ok = add_entry(ac, arg, fullname);
free (fullname); cmd_free (fullname);
} }
} }
else else
@ -278,7 +277,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
if (NULL != dirpart) if (NULL != dirpart)
{ {
free (dirpart); cmd_free (dirpart);
} }
return ok; return ok;
@ -298,7 +297,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
INT len; INT len;
BOOL bQuoted = FALSE; BOOL bQuoted = FALSE;
arg = malloc (sizeof (LPTSTR)); arg = cmd_alloc (sizeof (LPTSTR));
if (!arg) if (!arg)
return NULL; return NULL;
*arg = NULL; *arg = NULL;
@ -338,7 +337,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
/* a word was found */ /* a word was found */
if (s != start) if (s != start)
{ {
q = malloc (((len = s - start) + 1) * sizeof (TCHAR)); q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
if (!q) if (!q)
{ {
return NULL; return NULL;
@ -350,7 +349,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
{ {
if (! expand(&ac, &arg, q)) if (! expand(&ac, &arg, q))
{ {
free (q); cmd_free (q);
freep (arg); freep (arg);
return NULL; return NULL;
} }
@ -359,12 +358,12 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
{ {
if (! add_entry(&ac, &arg, q)) if (! add_entry(&ac, &arg, q))
{ {
free (q); cmd_free (q);
freep (arg); freep (arg);
return NULL; return NULL;
} }
} }
free (q); cmd_free (q);
} }
/* adjust string pointer if quoted (") */ /* adjust string pointer if quoted (") */
@ -400,9 +399,9 @@ VOID freep (LPTSTR *p)
q = p; q = p;
while (*q) while (*q)
free(*q++); cmd_free(*q++);
free(p); cmd_free(p);
} }
@ -457,7 +456,7 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
DWORD dwRead; DWORD dwRead;
INT len; INT len;
#ifdef _UNICODE #ifdef _UNICODE
lpString = malloc(nBufferLength); lpString = cmd_alloc(nBufferLength);
#else #else
lpString = lpBuffer; lpString = lpBuffer;
#endif #endif
@ -479,7 +478,7 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
lpString[len++] = _T('\0'); lpString[len++] = _T('\0');
#ifdef _UNICODE #ifdef _UNICODE
MultiByteToWideChar(CP_ACP, 0, lpString, len, lpBuffer, len); MultiByteToWideChar(CP_ACP, 0, lpString, len, lpBuffer, len);
free(lpString); cmd_free(lpString);
#endif #endif
return TRUE; return TRUE;
} }

View file

@ -30,7 +30,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_MOVE #ifdef INCLUDE_CMD_MOVE

View file

@ -11,7 +11,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_MSGBOX #ifdef INCLUDE_CMD_MSGBOX

View file

@ -26,7 +26,6 @@
* Remove all hardcode string to En.rc * Remove all hardcode string to En.rc
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_PATH #ifdef INCLUDE_CMD_PATH
@ -52,7 +51,7 @@ INT cmd_path (LPTSTR cmd, LPTSTR param)
LPTSTR pszBuffer; LPTSTR pszBuffer;
TCHAR szMsg[RC_STRING_MAX_SIZE]; TCHAR szMsg[RC_STRING_MAX_SIZE];
pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE); dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
if (dwBuffer == 0) if (dwBuffer == 0)
{ {
@ -62,12 +61,12 @@ INT cmd_path (LPTSTR cmd, LPTSTR param)
} }
else if (dwBuffer > ENV_BUFFER_SIZE) else if (dwBuffer > ENV_BUFFER_SIZE)
{ {
pszBuffer = (LPTSTR)realloc (pszBuffer, dwBuffer * sizeof (TCHAR)); pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE); GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
} }
ConOutPrintf (_T("PATH=%s\n"), pszBuffer); ConOutPrintf (_T("PATH=%s\n"), pszBuffer);
free (pszBuffer); cmd_free (pszBuffer);
return 0; return 0;
} }

View file

@ -18,7 +18,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_PAUSE #ifdef INCLUDE_CMD_PAUSE

View file

@ -5,6 +5,7 @@
#endif//_MSC_VER #endif//_MSC_VER
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#include <windows.h> #include <windows.h>
#include <winnt.h> #include <winnt.h>
@ -23,7 +24,11 @@
#define NTOS_MODE_USER #define NTOS_MODE_USER
#include <ndk/ntndk.h> #include <ndk/ntndk.h>
#include "resource.h"
#include "cmd.h" #include "cmd.h"
#include "config.h" #include "config.h"
#include "batch.h" #include "batch.h"
#include <reactos/resource.h>

View file

@ -47,7 +47,6 @@
* Remove all hardcode string to En.rc * Remove all hardcode string to En.rc
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* /*
* print the command-line prompt * print the command-line prompt

View file

@ -21,7 +21,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_RENAME #ifdef INCLUDE_CMD_RENAME

View file

@ -12,7 +12,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_SCREEN #ifdef INCLUDE_CMD_SCREEN

View file

@ -5,7 +5,7 @@
* History: * History:
* *
* 06/14/97 (Tim Norman) * 06/14/97 (Tim Norman)
* changed static var in set() to a malloc'd space to pass to putenv. * changed static var in set() to a cmd_alloc'd space to pass to putenv.
* need to find a better way to do this, since it seems it is wasting * need to find a better way to do this, since it seems it is wasting
* memory when variables are redefined. * memory when variables are redefined.
* *
@ -35,9 +35,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include <malloc.h>
#include <stdio.h>
#include "resource.h"
#ifdef INCLUDE_CMD_SET #ifdef INCLUDE_CMD_SET
@ -141,7 +138,7 @@ INT cmd_set (LPTSTR cmd, LPTSTR param)
LPTSTR pszBuffer; LPTSTR pszBuffer;
DWORD dwBuffer; DWORD dwBuffer;
pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
dwBuffer = GetEnvironmentVariable (param, pszBuffer, ENV_BUFFER_SIZE); dwBuffer = GetEnvironmentVariable (param, pszBuffer, ENV_BUFFER_SIZE);
if (dwBuffer == 0) if (dwBuffer == 0)
{ {
@ -151,12 +148,12 @@ INT cmd_set (LPTSTR cmd, LPTSTR param)
} }
else if (dwBuffer > ENV_BUFFER_SIZE) else if (dwBuffer > ENV_BUFFER_SIZE)
{ {
pszBuffer = (LPTSTR)realloc (pszBuffer, dwBuffer * sizeof (TCHAR)); pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
GetEnvironmentVariable (param, pszBuffer, dwBuffer); GetEnvironmentVariable (param, pszBuffer, dwBuffer);
} }
ConOutPrintf (_T("%s\n"), pszBuffer); ConOutPrintf (_T("%s\n"), pszBuffer);
free (pszBuffer); cmd_free (pszBuffer);
return 0; return 0;
} }

View file

@ -24,7 +24,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
/* /*

View file

@ -12,7 +12,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_START #ifdef INCLUDE_CMD_START
@ -90,7 +89,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
freep (arg); freep (arg);
/* get comspec */ /* get comspec */
comspec = malloc ( MAX_PATH * sizeof(TCHAR)); comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
if (comspec == NULL) if (comspec == NULL)
{ {
error_out_of_memory(); error_out_of_memory();
@ -109,7 +108,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
{ {
if (size > MAX_PATH) if (size > MAX_PATH)
{ {
comspec = realloc(comspec,size * sizeof(TCHAR) ); comspec = cmd_realloc(comspec,size * sizeof(TCHAR) );
if (comspec==NULL) if (comspec==NULL)
{ {
return 1; return 1;
@ -127,21 +126,21 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
_tcscat(RestWithoutArgs,_T("\"")); _tcscat(RestWithoutArgs,_T("\""));
} }
rest = malloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR)); rest = cmd_alloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR));
if (rest == NULL) if (rest == NULL)
{ {
if(comspec != NULL) if(comspec != NULL)
free(comspec); cmd_free(comspec);
error_out_of_memory(); error_out_of_memory();
return 1; return 1;
} }
param =malloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR)); param =cmd_alloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR));
if (rest == NULL) if (rest == NULL)
{ {
if(comspec != NULL) if(comspec != NULL)
free(comspec); cmd_free(comspec);
free(rest); cmd_free(rest);
error_out_of_memory(); error_out_of_memory();
return 1; return 1;
} }
@ -210,12 +209,12 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
ConErrResPuts (STRING_FREE_ERROR1); ConErrResPuts (STRING_FREE_ERROR1);
if (rest != NULL) if (rest != NULL)
free(rest); cmd_free(rest);
if (param != NULL) if (param != NULL)
free(param); cmd_free(param);
if (comspec != NULL) if (comspec != NULL)
free(comspec); cmd_free(comspec);
return 0; return 0;
} }
@ -226,13 +225,13 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
error_bad_command (); error_bad_command ();
if (rest != NULL) if (rest != NULL)
free(rest); cmd_free(rest);
if (param != NULL) if (param != NULL)
free(param); cmd_free(param);
if (comspec != NULL) if (comspec != NULL)
free(comspec); cmd_free(comspec);
return 1; return 1;
} }
@ -314,13 +313,13 @@ INT cmd_start (LPTSTR First, LPTSTR Rest)
if (rest != NULL) if (rest != NULL)
free(rest); cmd_free(rest);
if (param != NULL) if (param != NULL)
free(param); cmd_free(param);
if (comspec != NULL) if (comspec != NULL)
free(comspec); cmd_free(comspec);
return 0; return 0;
} }

View file

@ -25,7 +25,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_TIME #ifdef INCLUDE_CMD_TIME

View file

@ -8,7 +8,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_TIMER #ifdef INCLUDE_CMD_TIMER

View file

@ -10,7 +10,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_TITLE #ifdef INCLUDE_CMD_TITLE

View file

@ -27,7 +27,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_TYPE #ifdef INCLUDE_CMD_TYPE

View file

@ -22,8 +22,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#include <reactos/resource.h>
VOID ShortVersion (VOID) VOID ShortVersion (VOID)

View file

@ -19,7 +19,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_VERIFY #ifdef INCLUDE_CMD_VERIFY

View file

@ -21,7 +21,6 @@
*/ */
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#ifdef INCLUDE_CMD_VOL #ifdef INCLUDE_CMD_VOL

View file

@ -151,11 +151,11 @@ SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pExtensio
/* load environment varable PATH into buffer */ /* load environment varable PATH into buffer */
pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE); dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
if (dwBuffer > ENV_BUFFER_SIZE) if (dwBuffer > ENV_BUFFER_SIZE)
{ {
pszBuffer = (LPTSTR)realloc (pszBuffer, dwBuffer * sizeof (TCHAR)); pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer); GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer);
} }
@ -194,12 +194,12 @@ SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pExtensio
#ifdef _DEBUG #ifdef _DEBUG
DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer); DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
#endif #endif
free (pszBuffer); cmd_free (pszBuffer);
_tcscpy (pFullName, szPathBuffer); _tcscpy (pFullName, szPathBuffer);
return TRUE; return TRUE;
} }
} }
free (pszBuffer); cmd_free (pszBuffer);
return FALSE; return FALSE;
} }
@ -216,11 +216,11 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
DebugPrintf (_T("SearchForExecutable: \'%s\'\n"), pFileName); DebugPrintf (_T("SearchForExecutable: \'%s\'\n"), pFileName);
#endif #endif
/* load environment varable PATHEXT */ /* load environment varable PATHEXT */
pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR)); pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszBuffer, ENV_BUFFER_SIZE); dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszBuffer, ENV_BUFFER_SIZE);
if (dwBuffer > ENV_BUFFER_SIZE) if (dwBuffer > ENV_BUFFER_SIZE)
{ {
pszBuffer = (LPTSTR)realloc (pszBuffer, dwBuffer * sizeof (TCHAR)); pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
GetEnvironmentVariable (_T("PATHEXT"), pszBuffer, dwBuffer); GetEnvironmentVariable (_T("PATHEXT"), pszBuffer, dwBuffer);
} }
else if (0 == dwBuffer) else if (0 == dwBuffer)
@ -244,13 +244,13 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
{ {
if (0 == _tcsicmp(pCh, pExt)) if (0 == _tcsicmp(pCh, pExt))
{ {
free(pszBuffer); cmd_free(pszBuffer);
free(pszBuffer2); cmd_free(pszBuffer2);
return SearchForExecutableSingle(pFileName, pFullName, NULL); return SearchForExecutableSingle(pFileName, pFullName, NULL);
} }
pCh = _tcstok(NULL, _T(";")); pCh = _tcstok(NULL, _T(";"));
} }
free(pszBuffer2); cmd_free(pszBuffer2);
} }
} }
@ -259,13 +259,13 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
{ {
if (SearchForExecutableSingle(pFileName, pFullName, pCh)) if (SearchForExecutableSingle(pFileName, pFullName, pCh))
{ {
free(pszBuffer); cmd_free(pszBuffer);
return TRUE; return TRUE;
} }
pCh = _tcstok(NULL, _T(";")); pCh = _tcstok(NULL, _T(";"));
} }
free(pszBuffer); cmd_free(pszBuffer);
return FALSE; return FALSE;
} }

View file

@ -17,7 +17,6 @@
#include <precomp.h> #include <precomp.h>
#include "resource.h"
#if ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) ) #if ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) )