From df91a99233a9e965cd8dd88b59952f2bdb3af3da Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Wed, 1 Aug 2007 10:17:13 +0000 Subject: [PATCH] - 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 --- reactos/base/shell/cmd/alias.c | 35 ++++---- reactos/base/shell/cmd/attrib.c | 1 - reactos/base/shell/cmd/batch.c | 23 +++-- reactos/base/shell/cmd/beep.c | 1 - reactos/base/shell/cmd/call.c | 5 +- reactos/base/shell/cmd/chcp.c | 1 - reactos/base/shell/cmd/choice.c | 1 - reactos/base/shell/cmd/cls.c | 1 - reactos/base/shell/cmd/cmd.c | 58 ++++++------- reactos/base/shell/cmd/cmd.h | 2 + reactos/base/shell/cmd/cmd.rbuild | 1 + reactos/base/shell/cmd/cmddbg.c | 140 ++++++++++++++++++++++++++++++ reactos/base/shell/cmd/cmddbg.h | 22 +++++ reactos/base/shell/cmd/cmdinput.c | 1 - reactos/base/shell/cmd/cmdtable.c | 1 - reactos/base/shell/cmd/color.c | 1 - reactos/base/shell/cmd/console.c | 21 ++--- reactos/base/shell/cmd/copy.c | 11 ++- reactos/base/shell/cmd/date.c | 1 - reactos/base/shell/cmd/del.c | 1 - reactos/base/shell/cmd/delay.c | 1 - reactos/base/shell/cmd/dir.c | 35 ++++---- reactos/base/shell/cmd/dirstack.c | 11 ++- reactos/base/shell/cmd/echo.c | 1 - reactos/base/shell/cmd/error.c | 1 - reactos/base/shell/cmd/filecomp.c | 15 ++-- reactos/base/shell/cmd/for.c | 3 +- reactos/base/shell/cmd/free.c | 1 - reactos/base/shell/cmd/goto.c | 1 - reactos/base/shell/cmd/history.c | 22 ++--- reactos/base/shell/cmd/if.c | 1 - reactos/base/shell/cmd/internal.c | 7 +- reactos/base/shell/cmd/label.c | 1 - reactos/base/shell/cmd/locale.c | 1 - reactos/base/shell/cmd/main.c | 1 - reactos/base/shell/cmd/memory.c | 1 - reactos/base/shell/cmd/misc.c | 31 ++++--- reactos/base/shell/cmd/move.c | 1 - reactos/base/shell/cmd/msgbox.c | 1 - reactos/base/shell/cmd/path.c | 7 +- reactos/base/shell/cmd/pause.c | 1 - reactos/base/shell/cmd/precomp.h | 5 ++ reactos/base/shell/cmd/prompt.c | 1 - reactos/base/shell/cmd/ren.c | 1 - reactos/base/shell/cmd/screen.c | 1 - reactos/base/shell/cmd/set.c | 11 +-- reactos/base/shell/cmd/shift.c | 1 - reactos/base/shell/cmd/start.c | 33 ++++--- reactos/base/shell/cmd/time.c | 1 - reactos/base/shell/cmd/timer.c | 1 - reactos/base/shell/cmd/title.c | 1 - reactos/base/shell/cmd/type.c | 1 - reactos/base/shell/cmd/ver.c | 2 - reactos/base/shell/cmd/verify.c | 1 - reactos/base/shell/cmd/vol.c | 1 - reactos/base/shell/cmd/where.c | 22 ++--- reactos/base/shell/cmd/window.c | 1 - 57 files changed, 335 insertions(+), 221 deletions(-) create mode 100644 reactos/base/shell/cmd/cmddbg.c create mode 100644 reactos/base/shell/cmd/cmddbg.h diff --git a/reactos/base/shell/cmd/alias.c b/reactos/base/shell/cmd/alias.c index 06509e39507..d09c7a0485a 100644 --- a/reactos/base/shell/cmd/alias.c +++ b/reactos/base/shell/cmd/alias.c @@ -31,7 +31,6 @@ #include -#include "resource.h" #ifdef FEATURE_ALIASES @@ -89,9 +88,9 @@ DeleteAlias (LPTSTR pszName) prev->next = ptr->next; else lpFirst = ptr->next; - free (ptr->lpName); - free (ptr->lpSubst); - free (ptr); + cmd_free (ptr->lpName); + cmd_free (ptr->lpSubst); + cmd_free (ptr); return; } prev = ptr; @@ -111,14 +110,14 @@ AddAlias (LPTSTR name, LPTSTR subst) { if (!_tcsicmp (ptr->lpName, name)) { - s = (LPTSTR)malloc ((_tcslen (subst) + 1)*sizeof(TCHAR)); + s = (LPTSTR)cmd_alloc ((_tcslen (subst) + 1)*sizeof(TCHAR)); if (!s) { error_out_of_memory (); return; } - free (ptr->lpSubst); + cmd_free (ptr->lpSubst); ptr->lpSubst = s; _tcscpy (ptr->lpSubst, subst); return; @@ -126,27 +125,27 @@ AddAlias (LPTSTR name, LPTSTR subst) ptr = ptr->next; } - ptr = (LPALIAS)malloc (sizeof (ALIAS)); + ptr = (LPALIAS)cmd_alloc (sizeof (ALIAS)); if (!ptr) return; 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) { error_out_of_memory (); - free (ptr); + cmd_free (ptr); return; } _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) { error_out_of_memory (); - free (ptr->lpName); - free (ptr); + cmd_free (ptr->lpName); + cmd_free (ptr); return; } _tcscpy (ptr->lpSubst, subst); @@ -220,14 +219,14 @@ VOID DestroyAlias (VOID) lpLast = lpFirst; lpFirst = lpLast->next; - free (lpLast->lpName); - free (lpLast->lpSubst); - free (lpLast); + cmd_free (lpLast->lpName); + cmd_free (lpLast->lpSubst); + cmd_free (lpLast); } - free (lpFirst->lpName); - free (lpFirst->lpSubst); - free (lpFirst); + cmd_free (lpFirst->lpName); + cmd_free (lpFirst->lpSubst); + cmd_free (lpFirst); lpFirst = NULL; lpLast = NULL; diff --git a/reactos/base/shell/cmd/attrib.c b/reactos/base/shell/cmd/attrib.c index 5b6b0445978..c207657bb74 100644 --- a/reactos/base/shell/cmd/attrib.c +++ b/reactos/base/shell/cmd/attrib.c @@ -33,7 +33,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_ATTRIB diff --git a/reactos/base/shell/cmd/batch.c b/reactos/base/shell/cmd/batch.c index 215793fe167..d59dfa54e85 100644 --- a/reactos/base/shell/cmd/batch.c +++ b/reactos/base/shell/cmd/batch.c @@ -39,7 +39,7 @@ * Implementation of FOR command * * 20-Jul-1998 (John P Price ) - * added error checking after malloc calls + * added error checking after cmd_alloc calls * * 27-Jul-1998 (John P Price ) * added config.h include @@ -59,7 +59,6 @@ */ #include -#include "resource.h" /* The stack of current batch contexts. @@ -114,7 +113,7 @@ LPTSTR FindArg (INT n) 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 */ if (dp == NULL) @@ -188,19 +187,19 @@ VOID ExitBatch (LPTSTR msg) } if (bc->params) - free(bc->params); + cmd_free(bc->params); if (bc->forproto) - free(bc->forproto); + cmd_free(bc->forproto); if (bc->ffind) - free(bc->ffind); + cmd_free(bc->ffind); /* Preserve echo state across batch calls */ bEcho = bc->bEcho; bc = bc->prev; - free(t); + cmd_free(t); } if (msg && *msg) @@ -241,7 +240,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param) if (bc == NULL) { /* 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) { @@ -260,7 +259,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param) /* Then we are transferring to another batch */ CloseHandle (bc->hBatchFile); bc->hBatchFile = INVALID_HANDLE_VALUE; - free (bc->params); + cmd_free (bc->params); } 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 // - 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) { memset (bc->raw_params, 0, _tcslen(bc->raw_params) * sizeof(TCHAR)); @@ -378,7 +377,7 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho) else { /* 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(); return NULL; @@ -392,7 +391,7 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho) if (fv == NULL) { /* Null indicates no more files.. */ - free (bc->ffind); /* free the buffer */ + cmd_free (bc->ffind); /* free the buffer */ bc->ffind = NULL; bc->shiftlevel++; /* On to next list element */ continue; diff --git a/reactos/base/shell/cmd/beep.c b/reactos/base/shell/cmd/beep.c index f1b49d7e09f..75546f62083 100644 --- a/reactos/base/shell/cmd/beep.c +++ b/reactos/base/shell/cmd/beep.c @@ -25,7 +25,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_BEEP diff --git a/reactos/base/shell/cmd/call.c b/reactos/base/shell/cmd/call.c index 855ed9add28..975eac0da40 100644 --- a/reactos/base/shell/cmd/call.c +++ b/reactos/base/shell/cmd/call.c @@ -29,7 +29,6 @@ */ #include -#include "resource.h" /* @@ -56,7 +55,7 @@ INT cmd_call (LPTSTR cmd, LPTSTR param) nErrorLevel = 0; - n = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT)); + n = (LPBATCH_CONTEXT)cmd_alloc (sizeof (BATCH_CONTEXT)); if (n == NULL) { @@ -91,7 +90,7 @@ INT cmd_call (LPTSTR cmd, LPTSTR param) if (bc->hBatchFile == INVALID_HANDLE_VALUE) { bc = bc->prev; - free (n); + cmd_free (n); } return 0; diff --git a/reactos/base/shell/cmd/chcp.c b/reactos/base/shell/cmd/chcp.c index 9821c82f701..716b7ef36bf 100644 --- a/reactos/base/shell/cmd/chcp.c +++ b/reactos/base/shell/cmd/chcp.c @@ -12,7 +12,6 @@ */ #include -#include "resource.h" diff --git a/reactos/base/shell/cmd/choice.c b/reactos/base/shell/cmd/choice.c index 095a6b5e83d..55a06003230 100644 --- a/reactos/base/shell/cmd/choice.c +++ b/reactos/base/shell/cmd/choice.c @@ -20,7 +20,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_CHOICE diff --git a/reactos/base/shell/cmd/cls.c b/reactos/base/shell/cmd/cls.c index 4dfc61183c8..3519b439c0f 100644 --- a/reactos/base/shell/cmd/cls.c +++ b/reactos/base/shell/cmd/cls.c @@ -27,7 +27,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_CLS diff --git a/reactos/base/shell/cmd/cmd.c b/reactos/base/shell/cmd/cmd.c index 4a28527927a..c40a7fece7e 100644 --- a/reactos/base/shell/cmd/cmd.c +++ b/reactos/base/shell/cmd/cmd.c @@ -142,8 +142,6 @@ */ #include -#include -#include "resource.h" #ifndef NT_SUCCESS #define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0) @@ -351,10 +349,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest) #endif /* 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 */ - first = malloc ( (_tcslen(First) + 512) * sizeof(TCHAR)); + first = cmd_alloc ( (_tcslen(First) + 512) * sizeof(TCHAR)); if (first == NULL) { error_out_of_memory(); @@ -362,31 +360,31 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest) return ; } - rest = malloc ( (_tcslen(Rest) + 512) * sizeof(TCHAR)); + rest = cmd_alloc ( (_tcslen(Rest) + 512) * sizeof(TCHAR)); if (rest == NULL) { - free (first); + cmd_free (first); error_out_of_memory(); nErrorLevel = 1; return ; } - full = malloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); + full = cmd_alloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); if (full == NULL) { - free (first); - free (rest); + cmd_free (first); + cmd_free (rest); error_out_of_memory(); nErrorLevel = 1; return ; } - szFullName = malloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); + szFullName = cmd_alloc ( (_tcslen(Full) + 512) * sizeof(TCHAR)); if (full == NULL) { - free (first); - free (rest); - free (full); + cmd_free (first); + cmd_free (rest); + cmd_free (full); error_out_of_memory(); nErrorLevel = 1; return ; @@ -455,10 +453,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest) if (!working) ConErrResPuts (STRING_FREE_ERROR1); - free (first); - free (rest); - free (full); - free (szFullName); + cmd_free (first); + cmd_free (rest); + cmd_free (full); + cmd_free (szFullName); nErrorLevel = 1; return; } @@ -468,10 +466,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest) if (!SearchForExecutable (first, szFullName)) { error_bad_command (); - free (first); - free (rest); - free (full); - free (szFullName); + cmd_free (first); + cmd_free (rest); + cmd_free (full); + cmd_free (szFullName); nErrorLevel = 1; return; @@ -572,10 +570,10 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest) OutputCodePage = GetConsoleOutputCP(); SetConsoleTitle (szWindowTitle); - free(first); - free(rest); - free(full); - free (szFullName); + cmd_free(first); + cmd_free(rest); + cmd_free(full); + cmd_free (szFullName); } @@ -602,7 +600,7 @@ DoCommand (LPTSTR line) DebugPrintf (_T("DoCommand: (\'%s\')\n"), line); #endif /* DEBUG */ - com = malloc( (_tcslen(line) +512)*sizeof(TCHAR) ); + com = cmd_alloc( (_tcslen(line) +512)*sizeof(TCHAR) ); if (com == NULL) { error_out_of_memory(); @@ -646,7 +644,7 @@ DoCommand (LPTSTR line) if(_tcslen(com) > MAX_PATH) { error_bad_command(); - free(com); + cmd_free(com); 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; *retlen = needed; if ( *ret ) - free ( *ret ); - *ret = (LPTSTR)malloc ( *retlen * sizeof(TCHAR) ); + cmd_free ( *ret ); + *ret = (LPTSTR)cmd_alloc ( *retlen * sizeof(TCHAR) ); if ( !*ret ) SetLastError ( ERROR_OUTOFMEMORY ); return *ret != NULL; diff --git a/reactos/base/shell/cmd/cmd.h b/reactos/base/shell/cmd/cmd.h index 1fddd2394e1..04293d78f16 100644 --- a/reactos/base/shell/cmd/cmd.h +++ b/reactos/base/shell/cmd/cmd.h @@ -31,6 +31,8 @@ #include "cmdver.h" +#include "cmddbg.h" + #define BREAK_BATCHFILE 1 #define BREAK_OUTOFBATCH 2 #define BREAK_INPUT 3 diff --git a/reactos/base/shell/cmd/cmd.rbuild b/reactos/base/shell/cmd/cmd.rbuild index b869133e866..9ba127d909a 100644 --- a/reactos/base/shell/cmd/cmd.rbuild +++ b/reactos/base/shell/cmd/cmd.rbuild @@ -17,6 +17,7 @@ choice.c cls.c cmd.c + cmddbg.c cmdinput.c cmdtable.c color.c diff --git a/reactos/base/shell/cmd/cmddbg.c b/reactos/base/shell/cmd/cmddbg.c new file mode 100644 index 00000000000..11b9223ec45 --- /dev/null +++ b/reactos/base/shell/cmd/cmddbg.c @@ -0,0 +1,140 @@ +#include + +#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 */ diff --git a/reactos/base/shell/cmd/cmddbg.h b/reactos/base/shell/cmd/cmddbg.h new file mode 100644 index 00000000000..897b8b83160 --- /dev/null +++ b/reactos/base/shell/cmd/cmddbg.h @@ -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 diff --git a/reactos/base/shell/cmd/cmdinput.c b/reactos/base/shell/cmd/cmdinput.c index 6de4b0f9acb..0a9e297ca21 100644 --- a/reactos/base/shell/cmd/cmdinput.c +++ b/reactos/base/shell/cmd/cmdinput.c @@ -98,7 +98,6 @@ */ #include -#include "resource.h" SHORT maxx; diff --git a/reactos/base/shell/cmd/cmdtable.c b/reactos/base/shell/cmd/cmdtable.c index 848c2e50212..448e5888fdc 100644 --- a/reactos/base/shell/cmd/cmdtable.c +++ b/reactos/base/shell/cmd/cmdtable.c @@ -18,7 +18,6 @@ */ #include -#include "resource.h" /* a list of all the internal commands, associating their command names */ diff --git a/reactos/base/shell/cmd/color.c b/reactos/base/shell/cmd/color.c index 05cef16aeb9..e3f00c95bf7 100644 --- a/reactos/base/shell/cmd/color.c +++ b/reactos/base/shell/cmd/color.c @@ -21,7 +21,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_COLOR diff --git a/reactos/base/shell/cmd/console.c b/reactos/base/shell/cmd/console.c index d0c1435bae7..e6677c0eb3e 100644 --- a/reactos/base/shell/cmd/console.c +++ b/reactos/base/shell/cmd/console.c @@ -17,10 +17,7 @@ * Fixed ConPrintfPaging */ - - #include -#include "resource.h" #define OUTPUT_BUFFER_SIZE 4096 @@ -103,7 +100,7 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength) PCHAR pBuf; #ifdef _UNICODE - pBuf = (PCHAR)malloc(dwLength); + pBuf = (PCHAR)cmd_alloc(dwLength); #else pBuf = lpInput; #endif @@ -129,7 +126,7 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength) } #ifdef _UNICODE - free(pBuf); + cmd_free(pBuf); #endif SetConsoleMode (hFile, dwOldMode); @@ -169,7 +166,7 @@ VOID ConPuts(LPTSTR szText, DWORD nStdHandle) len = _tcslen(szText); #ifdef _UNICODE - pBuf = malloc(len + 1); + pBuf = cmd_alloc(len + 1); len = WideCharToMultiByte( OutputCodePage, 0, szText, len + 1, pBuf, len + 1, NULL, NULL) - 1; #else pBuf = szText; @@ -185,7 +182,7 @@ VOID ConPuts(LPTSTR szText, DWORD nStdHandle) &dwWritten, NULL); #ifdef _UNICODE - free(pBuf); + cmd_free(pBuf); #endif } @@ -219,7 +216,7 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle) len = _vstprintf (szOut, szFormat, arg_ptr); #ifdef _UNICODE - pBuf = malloc(len + 1); + pBuf = cmd_alloc(len + 1); len = WideCharToMultiByte( OutputCodePage, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1; #else pBuf = szOut; @@ -233,7 +230,7 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle) #ifdef _UNICODE - free(pBuf); + cmd_free(pBuf); #endif } @@ -287,7 +284,7 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa len = _vstprintf (szOut, szFormat, arg_ptr); #ifdef _UNICODE - pBuf = malloc(len + 1); + pBuf = cmd_alloc(len + 1); len = WideCharToMultiByte( OutputCodePage, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1; #else pBuf = szOut; @@ -311,7 +308,7 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa if(PagePrompt() != PROMPT_YES) { #ifdef _UNICODE - free(pBuf); + cmd_free(pBuf); #endif return 1; } @@ -323,7 +320,7 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa } #ifdef _UNICODE - free(pBuf); + cmd_free(pBuf); #endif return 0; } diff --git a/reactos/base/shell/cmd/copy.c b/reactos/base/shell/cmd/copy.c index ddd163725e7..dd5f65f4f20 100644 --- a/reactos/base/shell/cmd/copy.c +++ b/reactos/base/shell/cmd/copy.c @@ -32,7 +32,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_COPY @@ -264,7 +263,7 @@ copy (TCHAR source[MAX_PATH], { ConOutResPuts(STRING_COPY_ERROR3); - free (buffer); + cmd_free (buffer); CloseHandle (hFileDest); CloseHandle (hFileSrc); nErrorLevel = 1; @@ -375,7 +374,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param) nErrorLevel = 0; /* Get the envor value if it exists */ - evar = malloc(512 * sizeof(TCHAR)); + evar = cmd_alloc(512 * sizeof(TCHAR)); if (evar==NULL) size = 0; else { @@ -383,7 +382,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param) } if (size > 512) { - evar = realloc(evar,size * sizeof(TCHAR) ); + evar = cmd_realloc(evar,size * sizeof(TCHAR) ); if (evar!=NULL) { 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*/ @@ -873,7 +872,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param) FindClose(hFile); if (arg!=NULL) - free(arg); + cmd_free(arg); return 0; } diff --git a/reactos/base/shell/cmd/date.c b/reactos/base/shell/cmd/date.c index 6de715298e8..b1dda4f30a1 100644 --- a/reactos/base/shell/cmd/date.c +++ b/reactos/base/shell/cmd/date.c @@ -32,7 +32,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_DATE diff --git a/reactos/base/shell/cmd/del.c b/reactos/base/shell/cmd/del.c index 4102a3b14cd..28ef3f6069b 100644 --- a/reactos/base/shell/cmd/del.c +++ b/reactos/base/shell/cmd/del.c @@ -46,7 +46,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_DEL diff --git a/reactos/base/shell/cmd/delay.c b/reactos/base/shell/cmd/delay.c index 4b383102e33..eebbaf01cfb 100644 --- a/reactos/base/shell/cmd/delay.c +++ b/reactos/base/shell/cmd/delay.c @@ -10,7 +10,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_DELAY diff --git a/reactos/base/shell/cmd/dir.c b/reactos/base/shell/cmd/dir.c index 8e189e61113..71912ead218 100644 --- a/reactos/base/shell/cmd/dir.c +++ b/reactos/base/shell/cmd/dir.c @@ -135,7 +135,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_DIR @@ -365,19 +364,19 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */ cCurSwitch = _T(' '); if(ptrStart && ptrEnd) { - temp = malloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); + temp = cmd_alloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); if(!temp) return FALSE; memcpy(temp, ptrStart, (ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); temp[(ptrEnd - ptrStart + 1)] = _T('\0'); if(!add_entry(entries, params, temp)) { - free(temp); + cmd_free(temp); freep(*params); return FALSE; } - free(temp); + cmd_free(temp); ptrStart = NULL; ptrEnd = NULL; @@ -397,19 +396,19 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */ /* Process a character for parameter */ if ((cCurSwitch == _T(' ')) && ptrStart && ptrEnd) { - temp = malloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); + temp = cmd_alloc((ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); if(!temp) return FALSE; memcpy(temp, ptrStart, (ptrEnd - ptrStart) + 2 * sizeof (TCHAR)); temp[(ptrEnd - ptrStart + 1)] = _T('\0'); if(!add_entry(entries, params, temp)) { - free(temp); + cmd_free(temp); freep(*params); return FALSE; } - free(temp); + cmd_free(temp); ptrStart = NULL; ptrEnd = NULL; @@ -568,19 +567,19 @@ DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */ /* Terminate the parameters */ if(ptrStart && ptrEnd) { - temp = malloc((ptrEnd - ptrStart + 2) * sizeof(TCHAR)); + temp = cmd_alloc((ptrEnd - ptrStart + 2) * sizeof(TCHAR)); if(!temp) return FALSE; memcpy(temp, ptrStart, (ptrEnd - ptrStart + 1) * sizeof(TCHAR)); temp[(ptrEnd - ptrStart + 1)] = _T('\0'); if(!add_entry(entries, params, temp)) { - free(temp); + cmd_free(temp); freep(*params); return FALSE; } - free(temp); + cmd_free(temp); ptrStart = NULL; ptrEnd = NULL; @@ -1770,7 +1769,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */ _tcscat (szFullFileSpec, szFilespec); /* Prepare the linked list, first node is allocated */ - ptrStartNode = malloc(sizeof(DIRFINDLISTNODE)); + ptrStartNode = cmd_alloc(sizeof(DIRFINDLISTNODE)); if (ptrStartNode == NULL) { #ifdef _DEBUG @@ -1790,7 +1789,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */ if ((wfdFileInfo.dwFileAttributes & lpFlags->stAttribs.dwAttribMask ) == (lpFlags->stAttribs.dwAttribMask & lpFlags->stAttribs.dwAttribVal )) { - ptrNextNode->ptrNext = malloc(sizeof(DIRFINDLISTNODE)); + ptrNextNode->ptrNext = cmd_alloc(sizeof(DIRFINDLISTNODE)); if (ptrNextNode->ptrNext == NULL) { #ifdef _DEBUG @@ -1799,14 +1798,14 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */ while (ptrStartNode) { ptrNextNode = ptrStartNode->ptrNext; - free(ptrStartNode); + cmd_free(ptrStartNode); ptrStartNode = ptrNextNode; dwCount --; } 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! */ if (ptrNextNode->ptrNext) { @@ -1850,7 +1849,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */ ptrNextNode->ptrNext = NULL; /* 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) { #ifdef _DEBUG @@ -1859,7 +1858,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */ while (ptrStartNode) { ptrNextNode = ptrStartNode->ptrNext; - free(ptrStartNode); + cmd_free(ptrStartNode); ptrStartNode = ptrNextNode; dwCount --; } @@ -1887,7 +1886,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */ DirPrintFiles(ptrFileArray, dwCount, szFullPath, lpFlags); /* Free array */ - free(ptrFileArray); + cmd_free(ptrFileArray); if (CheckCtrlBreak(BREAK_INPUT)) return 1; @@ -1933,7 +1932,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */ while (ptrStartNode) { ptrNextNode = ptrStartNode->ptrNext; - free(ptrStartNode); + cmd_free(ptrStartNode); ptrStartNode = ptrNextNode; dwCount --; } diff --git a/reactos/base/shell/cmd/dirstack.c b/reactos/base/shell/cmd/dirstack.c index cfbcc15686f..8c1e0189b2c 100644 --- a/reactos/base/shell/cmd/dirstack.c +++ b/reactos/base/shell/cmd/dirstack.c @@ -15,7 +15,6 @@ */ #include -#include "resource.h" #ifdef FEATURE_DIRECTORY_STACK @@ -39,7 +38,7 @@ PushDirectory (LPTSTR pszPath) nErrorLevel = 0; - lpDir = (LPDIRENTRY)malloc (sizeof (DIRENTRY)); + lpDir = (LPDIRENTRY)cmd_alloc (sizeof (DIRENTRY)); if (!lpDir) { error_out_of_memory (); @@ -59,10 +58,10 @@ PushDirectory (LPTSTR pszPath) } lpStackTop = lpDir; - lpDir->pszPath = (LPTSTR)malloc ((_tcslen(pszPath)+1)*sizeof(TCHAR)); + lpDir->pszPath = (LPTSTR)cmd_alloc ((_tcslen(pszPath)+1)*sizeof(TCHAR)); if (!lpDir->pszPath) { - free (lpDir); + cmd_free (lpDir); error_out_of_memory (); return -1; } @@ -92,8 +91,8 @@ PopDirectory (VOID) else lpStackBottom = NULL; - free (lpDir->pszPath); - free (lpDir); + cmd_free (lpDir->pszPath); + cmd_free (lpDir); nStackDepth--; } diff --git a/reactos/base/shell/cmd/echo.c b/reactos/base/shell/cmd/echo.c index 088f3f9189b..326f2db790e 100644 --- a/reactos/base/shell/cmd/echo.c +++ b/reactos/base/shell/cmd/echo.c @@ -27,7 +27,6 @@ */ #include -#include "resource.h" INT CommandEcho (LPTSTR cmd, LPTSTR param) diff --git a/reactos/base/shell/cmd/error.c b/reactos/base/shell/cmd/error.c index e3784797235..7ecb86d27c4 100644 --- a/reactos/base/shell/cmd/error.c +++ b/reactos/base/shell/cmd/error.c @@ -21,7 +21,6 @@ */ #include -#include "resource.h" VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...) diff --git a/reactos/base/shell/cmd/filecomp.c b/reactos/base/shell/cmd/filecomp.c index cd5506aa7e0..049d69c92fd 100644 --- a/reactos/base/shell/cmd/filecomp.c +++ b/reactos/base/shell/cmd/filecomp.c @@ -21,7 +21,6 @@ */ #include -#include "cmd.h" #ifdef FEATURE_UNIX_FILENAME_COMPLETION @@ -490,8 +489,8 @@ VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix) FileName * File2; INT ret; - File1 = malloc(sizeof(FileName)); - File2 = malloc(sizeof(FileName)); + File1 = cmd_alloc(sizeof(FileName)); + File2 = cmd_alloc(sizeof(FileName)); if(!File1 || !File2) return 0; @@ -501,8 +500,8 @@ VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix) /* ret = _tcsicmp(File1->Name, File2->Name); */ ret = lstrcmpi(File1->Name, File2->Name); - free(File1); - free(File2); + cmd_free(File1); + cmd_free(File2); return ret; } @@ -628,7 +627,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) } /* Add the file to the list of files */ - FileList = realloc(FileList, ++FileListSize * sizeof(FileName)); + FileList = cmd_realloc(FileList, ++FileListSize * sizeof(FileName)); if(FileList == NULL) { @@ -651,7 +650,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) { _tcscpy(strOut,szOrginal); if(FileList != NULL) - free(FileList); + cmd_free(FileList); return; } @@ -741,7 +740,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) EndLength = _tcslen(strOut); DiffLength = EndLength - StartLength; if(FileList != NULL) - free(FileList); + cmd_free(FileList); } #endif diff --git a/reactos/base/shell/cmd/for.c b/reactos/base/shell/cmd/for.c index b503a57b141..27461f6a55b 100644 --- a/reactos/base/shell/cmd/for.c +++ b/reactos/base/shell/cmd/for.c @@ -31,7 +31,6 @@ */ #include -#include "resource.h" /* @@ -126,7 +125,7 @@ INT cmd_for (LPTSTR cmd, LPTSTR param) } /* 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; bc = lpNew; diff --git a/reactos/base/shell/cmd/free.c b/reactos/base/shell/cmd/free.c index f739cd3522f..7e08dc10bd5 100644 --- a/reactos/base/shell/cmd/free.c +++ b/reactos/base/shell/cmd/free.c @@ -12,7 +12,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_FREE diff --git a/reactos/base/shell/cmd/goto.c b/reactos/base/shell/cmd/goto.c index 0181dd2ceb1..8d444434d5e 100644 --- a/reactos/base/shell/cmd/goto.c +++ b/reactos/base/shell/cmd/goto.c @@ -27,7 +27,6 @@ */ #include -#include "resource.h" /* diff --git a/reactos/base/shell/cmd/history.c b/reactos/base/shell/cmd/history.c index 1499089c32d..6285687b0b5 100644 --- a/reactos/base/shell/cmd/history.c +++ b/reactos/base/shell/cmd/history.c @@ -139,8 +139,8 @@ VOID InitHistory(VOID) { size=0; - Top = malloc(sizeof(HIST_ENTRY)); - Bottom = malloc(sizeof(HIST_ENTRY)); + Top = cmd_alloc(sizeof(HIST_ENTRY)); + Bottom = cmd_alloc(sizeof(HIST_ENTRY)); Top->prev = Bottom; Top->next = NULL; @@ -161,8 +161,8 @@ VOID CleanHistory(VOID) while (Bottom->next!=Top) del(Bottom->next); - free(Top); - free(Bottom); + cmd_free(Top); + cmd_free(Bottom); } @@ -204,13 +204,13 @@ VOID del(LPHIST_ENTRY item) /*free string's mem*/ if (item->string) - free(item->string); + cmd_free(item->string); /*set links in prev and next item*/ item->next->prev=item->prev; item->prev->next=item->next; - free(item); + cmd_free(item); size--; } @@ -233,8 +233,8 @@ VOID add_before_last(LPTSTR string) return; /*allocte entry and string*/ - tmp=malloc(sizeof(HIST_ENTRY)); - tmp->string=malloc((_tcslen(string)+1)*sizeof(TCHAR)); + tmp=cmd_alloc(sizeof(HIST_ENTRY)); + tmp->string=cmd_alloc((_tcslen(string)+1)*sizeof(TCHAR)); _tcscpy(tmp->string,string); /*set links*/ @@ -280,7 +280,7 @@ VOID add_at_bottom(LPTSTR string) /*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); /*save Bottom value*/ @@ -288,7 +288,7 @@ VOID add_at_bottom(LPTSTR string) /*create new void Bottom*/ - Bottom=malloc(sizeof(HIST_ENTRY)); + Bottom=cmd_alloc(sizeof(HIST_ENTRY)); Bottom->next=tmp; Bottom->prev=NULL; Bottom->string=NULL; @@ -401,7 +401,7 @@ VOID History (INT dir, LPTSTR commandline) /*first time History is called allocate mem*/ if (!history) { - history = malloc (history_size * sizeof (TCHAR)); + history = cmd_alloc (history_size * sizeof (TCHAR)); lines[0] = history; history[0] = 0; } diff --git a/reactos/base/shell/cmd/if.c b/reactos/base/shell/cmd/if.c index ebdfdf143f5..2019a12d17c 100644 --- a/reactos/base/shell/cmd/if.c +++ b/reactos/base/shell/cmd/if.c @@ -31,7 +31,6 @@ */ #include -#include "resource.h" #define X_EXEC 1 diff --git a/reactos/base/shell/cmd/internal.c b/reactos/base/shell/cmd/internal.c index a1b201208c9..8be47402686 100644 --- a/reactos/base/shell/cmd/internal.c +++ b/reactos/base/shell/cmd/internal.c @@ -138,7 +138,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_CHDIR @@ -154,7 +153,7 @@ VOID InitLastPath (VOID) VOID FreeLastPath (VOID) { if (lpLastPath) - free (lpLastPath); + cmd_free (lpLastPath); } /* 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 (_tcslen(param)) { - LPTSTR NewCommand = malloc((_tcslen(param)+4)*sizeof(TCHAR)); + LPTSTR NewCommand = cmd_alloc((_tcslen(param)+4)*sizeof(TCHAR)); _tcscpy(NewCommand, param); _tcscat(NewCommand, _T(" /?")); DoCommand(NewCommand); - free(NewCommand); + cmd_free(NewCommand); } /* Else, display detailed commands list */ else diff --git a/reactos/base/shell/cmd/label.c b/reactos/base/shell/cmd/label.c index c34fe7258a7..f2b2a6031d7 100644 --- a/reactos/base/shell/cmd/label.c +++ b/reactos/base/shell/cmd/label.c @@ -18,7 +18,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_LABEL diff --git a/reactos/base/shell/cmd/locale.c b/reactos/base/shell/cmd/locale.c index f8e988e2c1d..fcdd660049b 100644 --- a/reactos/base/shell/cmd/locale.c +++ b/reactos/base/shell/cmd/locale.c @@ -12,7 +12,6 @@ */ #include -#include "resource.h" TCHAR cDateSeparator; diff --git a/reactos/base/shell/cmd/main.c b/reactos/base/shell/cmd/main.c index 85bb80b7542..9f75432e57a 100644 --- a/reactos/base/shell/cmd/main.c +++ b/reactos/base/shell/cmd/main.c @@ -1,5 +1,4 @@ #include -#include "resource.h" #ifdef _UNICODE extern int _main (void); diff --git a/reactos/base/shell/cmd/memory.c b/reactos/base/shell/cmd/memory.c index 2a917ffd8d1..d5e8048a94e 100644 --- a/reactos/base/shell/cmd/memory.c +++ b/reactos/base/shell/cmd/memory.c @@ -12,7 +12,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_MEMORY diff --git a/reactos/base/shell/cmd/misc.c b/reactos/base/shell/cmd/misc.c index bec42b4f8a2..87f62ef4082 100644 --- a/reactos/base/shell/cmd/misc.c +++ b/reactos/base/shell/cmd/misc.c @@ -33,7 +33,6 @@ */ #include -#include "resource.h" /* @@ -200,7 +199,7 @@ BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry) LPTSTR q; LPTSTR *oldarg; - q = malloc ((_tcslen(entry) + 1) * sizeof (TCHAR)); + q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR)); if (NULL == q) { return FALSE; @@ -208,7 +207,7 @@ BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry) _tcscpy (q, entry); oldarg = *arg; - *arg = realloc (oldarg, (*ac + 2) * sizeof (LPTSTR)); + *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR)); if (NULL == *arg) { *arg = oldarg; @@ -233,7 +232,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern) pathend = _tcsrchr (pattern, _T('\\')); if (NULL != pathend) { - dirpart = malloc((pathend - pattern + 2) * sizeof(TCHAR)); + dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR)); if (NULL == dirpart) { return FALSE; @@ -252,7 +251,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern) { 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) { ok = FALSE; @@ -261,7 +260,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern) { _tcscat (_tcscpy (fullname, dirpart), FindData.cFileName); ok = add_entry(ac, arg, fullname); - free (fullname); + cmd_free (fullname); } } else @@ -278,7 +277,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern) if (NULL != dirpart) { - free (dirpart); + cmd_free (dirpart); } return ok; @@ -298,7 +297,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards) INT len; BOOL bQuoted = FALSE; - arg = malloc (sizeof (LPTSTR)); + arg = cmd_alloc (sizeof (LPTSTR)); if (!arg) return NULL; *arg = NULL; @@ -338,7 +337,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards) /* a word was found */ if (s != start) { - q = malloc (((len = s - start) + 1) * sizeof (TCHAR)); + q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR)); if (!q) { return NULL; @@ -350,7 +349,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards) { if (! expand(&ac, &arg, q)) { - free (q); + cmd_free (q); freep (arg); return NULL; } @@ -359,12 +358,12 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards) { if (! add_entry(&ac, &arg, q)) { - free (q); + cmd_free (q); freep (arg); return NULL; } } - free (q); + cmd_free (q); } /* adjust string pointer if quoted (") */ @@ -400,9 +399,9 @@ VOID freep (LPTSTR *p) q = p; 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; INT len; #ifdef _UNICODE - lpString = malloc(nBufferLength); + lpString = cmd_alloc(nBufferLength); #else lpString = lpBuffer; #endif @@ -479,7 +478,7 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength) lpString[len++] = _T('\0'); #ifdef _UNICODE MultiByteToWideChar(CP_ACP, 0, lpString, len, lpBuffer, len); - free(lpString); + cmd_free(lpString); #endif return TRUE; } diff --git a/reactos/base/shell/cmd/move.c b/reactos/base/shell/cmd/move.c index 2ae9d89c4d3..e456dd8e81b 100644 --- a/reactos/base/shell/cmd/move.c +++ b/reactos/base/shell/cmd/move.c @@ -30,7 +30,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_MOVE diff --git a/reactos/base/shell/cmd/msgbox.c b/reactos/base/shell/cmd/msgbox.c index f512bb7cf0f..72aaf6fdd3c 100644 --- a/reactos/base/shell/cmd/msgbox.c +++ b/reactos/base/shell/cmd/msgbox.c @@ -11,7 +11,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_MSGBOX diff --git a/reactos/base/shell/cmd/path.c b/reactos/base/shell/cmd/path.c index dc376e1a934..fd4bb0fb3d9 100644 --- a/reactos/base/shell/cmd/path.c +++ b/reactos/base/shell/cmd/path.c @@ -26,7 +26,6 @@ * Remove all hardcode string to En.rc */ #include -#include "resource.h" #ifdef INCLUDE_CMD_PATH @@ -52,7 +51,7 @@ INT cmd_path (LPTSTR cmd, LPTSTR param) LPTSTR pszBuffer; 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); if (dwBuffer == 0) { @@ -62,12 +61,12 @@ INT cmd_path (LPTSTR cmd, LPTSTR param) } 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); } ConOutPrintf (_T("PATH=%s\n"), pszBuffer); - free (pszBuffer); + cmd_free (pszBuffer); return 0; } diff --git a/reactos/base/shell/cmd/pause.c b/reactos/base/shell/cmd/pause.c index 47fbccc7817..50889174fad 100644 --- a/reactos/base/shell/cmd/pause.c +++ b/reactos/base/shell/cmd/pause.c @@ -18,7 +18,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_PAUSE diff --git a/reactos/base/shell/cmd/precomp.h b/reactos/base/shell/cmd/precomp.h index 3fd7e6b22df..0c27a62d07e 100644 --- a/reactos/base/shell/cmd/precomp.h +++ b/reactos/base/shell/cmd/precomp.h @@ -5,6 +5,7 @@ #endif//_MSC_VER #include +#include #define WIN32_NO_STATUS #include #include @@ -23,7 +24,11 @@ #define NTOS_MODE_USER #include +#include "resource.h" + #include "cmd.h" #include "config.h" #include "batch.h" +#include + diff --git a/reactos/base/shell/cmd/prompt.c b/reactos/base/shell/cmd/prompt.c index d730fc3cbaf..5885e786292 100644 --- a/reactos/base/shell/cmd/prompt.c +++ b/reactos/base/shell/cmd/prompt.c @@ -47,7 +47,6 @@ * Remove all hardcode string to En.rc */ #include -#include "resource.h" /* * print the command-line prompt diff --git a/reactos/base/shell/cmd/ren.c b/reactos/base/shell/cmd/ren.c index 83f0be71e59..3b073914b7d 100644 --- a/reactos/base/shell/cmd/ren.c +++ b/reactos/base/shell/cmd/ren.c @@ -21,7 +21,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_RENAME diff --git a/reactos/base/shell/cmd/screen.c b/reactos/base/shell/cmd/screen.c index 315e7c83c0f..8e1009b6b5e 100644 --- a/reactos/base/shell/cmd/screen.c +++ b/reactos/base/shell/cmd/screen.c @@ -12,7 +12,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_SCREEN diff --git a/reactos/base/shell/cmd/set.c b/reactos/base/shell/cmd/set.c index 165682bf9f5..522c340bb0e 100644 --- a/reactos/base/shell/cmd/set.c +++ b/reactos/base/shell/cmd/set.c @@ -5,7 +5,7 @@ * History: * * 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 * memory when variables are redefined. * @@ -35,9 +35,6 @@ */ #include -#include -#include -#include "resource.h" #ifdef INCLUDE_CMD_SET @@ -141,7 +138,7 @@ INT cmd_set (LPTSTR cmd, LPTSTR param) LPTSTR pszBuffer; 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); if (dwBuffer == 0) { @@ -151,12 +148,12 @@ INT cmd_set (LPTSTR cmd, LPTSTR param) } 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); } ConOutPrintf (_T("%s\n"), pszBuffer); - free (pszBuffer); + cmd_free (pszBuffer); return 0; } diff --git a/reactos/base/shell/cmd/shift.c b/reactos/base/shell/cmd/shift.c index f806b385d46..4ccdf51d132 100644 --- a/reactos/base/shell/cmd/shift.c +++ b/reactos/base/shell/cmd/shift.c @@ -24,7 +24,6 @@ */ #include -#include "resource.h" /* diff --git a/reactos/base/shell/cmd/start.c b/reactos/base/shell/cmd/start.c index 21f51a5229d..9782c545d9c 100644 --- a/reactos/base/shell/cmd/start.c +++ b/reactos/base/shell/cmd/start.c @@ -12,7 +12,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_START @@ -90,7 +89,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) freep (arg); /* get comspec */ - comspec = malloc ( MAX_PATH * sizeof(TCHAR)); + comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR)); if (comspec == NULL) { error_out_of_memory(); @@ -109,7 +108,7 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) { if (size > MAX_PATH) { - comspec = realloc(comspec,size * sizeof(TCHAR) ); + comspec = cmd_realloc(comspec,size * sizeof(TCHAR) ); if (comspec==NULL) { return 1; @@ -127,21 +126,21 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) _tcscat(RestWithoutArgs,_T("\"")); } - rest = malloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR)); + rest = cmd_alloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR)); if (rest == NULL) { if(comspec != NULL) - free(comspec); + cmd_free(comspec); error_out_of_memory(); return 1; } - param =malloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR)); + param =cmd_alloc ( (_tcslen(RestWithoutArgs) + 1) * sizeof(TCHAR)); if (rest == NULL) { if(comspec != NULL) - free(comspec); - free(rest); + cmd_free(comspec); + cmd_free(rest); error_out_of_memory(); return 1; } @@ -210,12 +209,12 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) ConErrResPuts (STRING_FREE_ERROR1); if (rest != NULL) - free(rest); + cmd_free(rest); if (param != NULL) - free(param); + cmd_free(param); if (comspec != NULL) - free(comspec); + cmd_free(comspec); return 0; } @@ -226,13 +225,13 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) error_bad_command (); if (rest != NULL) - free(rest); + cmd_free(rest); if (param != NULL) - free(param); + cmd_free(param); if (comspec != NULL) - free(comspec); + cmd_free(comspec); return 1; } @@ -314,13 +313,13 @@ INT cmd_start (LPTSTR First, LPTSTR Rest) if (rest != NULL) - free(rest); + cmd_free(rest); if (param != NULL) - free(param); + cmd_free(param); if (comspec != NULL) - free(comspec); + cmd_free(comspec); return 0; } diff --git a/reactos/base/shell/cmd/time.c b/reactos/base/shell/cmd/time.c index c42f39b7c74..c1277c9f640 100644 --- a/reactos/base/shell/cmd/time.c +++ b/reactos/base/shell/cmd/time.c @@ -25,7 +25,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_TIME diff --git a/reactos/base/shell/cmd/timer.c b/reactos/base/shell/cmd/timer.c index 34567dafa40..a5f10df1553 100644 --- a/reactos/base/shell/cmd/timer.c +++ b/reactos/base/shell/cmd/timer.c @@ -8,7 +8,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_TIMER diff --git a/reactos/base/shell/cmd/title.c b/reactos/base/shell/cmd/title.c index a82bb3c21b5..7f56fd63485 100644 --- a/reactos/base/shell/cmd/title.c +++ b/reactos/base/shell/cmd/title.c @@ -10,7 +10,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_TITLE diff --git a/reactos/base/shell/cmd/type.c b/reactos/base/shell/cmd/type.c index 6bc3164ac0b..a36bb562a1e 100644 --- a/reactos/base/shell/cmd/type.c +++ b/reactos/base/shell/cmd/type.c @@ -27,7 +27,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_TYPE diff --git a/reactos/base/shell/cmd/ver.c b/reactos/base/shell/cmd/ver.c index 02d30c89cb4..53fcff861a0 100644 --- a/reactos/base/shell/cmd/ver.c +++ b/reactos/base/shell/cmd/ver.c @@ -22,8 +22,6 @@ */ #include -#include "resource.h" -#include VOID ShortVersion (VOID) diff --git a/reactos/base/shell/cmd/verify.c b/reactos/base/shell/cmd/verify.c index 597c79dba00..e4a1145e93f 100644 --- a/reactos/base/shell/cmd/verify.c +++ b/reactos/base/shell/cmd/verify.c @@ -19,7 +19,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_VERIFY diff --git a/reactos/base/shell/cmd/vol.c b/reactos/base/shell/cmd/vol.c index 6239e14eac4..c26106df728 100644 --- a/reactos/base/shell/cmd/vol.c +++ b/reactos/base/shell/cmd/vol.c @@ -21,7 +21,6 @@ */ #include -#include "resource.h" #ifdef INCLUDE_CMD_VOL diff --git a/reactos/base/shell/cmd/where.c b/reactos/base/shell/cmd/where.c index 7fdcad8cca2..b41b8e42d87 100644 --- a/reactos/base/shell/cmd/where.c +++ b/reactos/base/shell/cmd/where.c @@ -151,11 +151,11 @@ SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pExtensio /* 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); 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); } @@ -194,12 +194,12 @@ SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pExtensio #ifdef _DEBUG DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer); #endif - free (pszBuffer); + cmd_free (pszBuffer); _tcscpy (pFullName, szPathBuffer); return TRUE; } } - free (pszBuffer); + cmd_free (pszBuffer); return FALSE; } @@ -216,11 +216,11 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName) DebugPrintf (_T("SearchForExecutable: \'%s\'\n"), pFileName); #endif /* 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); 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); } else if (0 == dwBuffer) @@ -244,13 +244,13 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName) { if (0 == _tcsicmp(pCh, pExt)) { - free(pszBuffer); - free(pszBuffer2); + cmd_free(pszBuffer); + cmd_free(pszBuffer2); return SearchForExecutableSingle(pFileName, pFullName, NULL); } pCh = _tcstok(NULL, _T(";")); } - free(pszBuffer2); + cmd_free(pszBuffer2); } } @@ -259,13 +259,13 @@ SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName) { if (SearchForExecutableSingle(pFileName, pFullName, pCh)) { - free(pszBuffer); + cmd_free(pszBuffer); return TRUE; } pCh = _tcstok(NULL, _T(";")); } - free(pszBuffer); + cmd_free(pszBuffer); return FALSE; } diff --git a/reactos/base/shell/cmd/window.c b/reactos/base/shell/cmd/window.c index 10ac14c1bf3..13c656f89a9 100644 --- a/reactos/base/shell/cmd/window.c +++ b/reactos/base/shell/cmd/window.c @@ -17,7 +17,6 @@ #include -#include "resource.h" #if ( defined(INCLUDE_CMD_WINDOW) || defined(INCLUDE_CMD_ACTIVATE) )