1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-05 17:28:47 +00:00

cmd: Use standard C functions for memory allocation.

This commit is contained in:
Alex Henrie 2022-12-07 22:47:19 -07:00 committed by Alexandre Julliard
parent 702b92ad23
commit 5792785879
5 changed files with 113 additions and 114 deletions

View File

@ -68,7 +68,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, BOOL called, WCHAR *startLabel, HA
prev_context = context;
context = LocalAlloc (LMEM_FIXED, sizeof (BATCH_CONTEXT));
context -> h = h;
context->batchfileW = heap_strdupW(file);
context->batchfileW = xstrdupW(file);
context -> command = command;
memset(context -> shift_count, 0x00, sizeof(context -> shift_count));
context -> prev_context = prev_context;
@ -110,8 +110,8 @@ void WCMD_batch (WCHAR *file, WCHAR *command, BOOL called, WCHAR *startLabel, HA
* to the caller's caller.
*/
heap_free(context->batchfileW);
LocalFree (context);
free(context->batchfileW);
LocalFree(context);
if ((prev_context != NULL) && (!called)) {
WINE_TRACE("Batch completed, but was not 'called' so skipping outer batch too\n");
prev_context -> skip_rest = TRUE;
@ -256,7 +256,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
const char *p;
cp = GetOEMCP();
bufA = heap_xalloc(noChars);
bufA = xalloc(noChars);
/* Save current file position */
filepos.QuadPart = 0;
@ -264,7 +264,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
status = ReadFile(h, bufA, noChars, &charsRead, NULL);
if (!status || charsRead == 0) {
heap_free(bufA);
free(bufA);
return NULL;
}
@ -279,7 +279,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, DWORD noChars, HANDLE h)
SetFilePointerEx(h, filepos, NULL, FILE_BEGIN);
i = MultiByteToWideChar(cp, 0, bufA, p - bufA, buf, noChars);
heap_free(bufA);
free(bufA);
}
else {
if (!charsRead) return NULL;
@ -454,11 +454,11 @@ void WCMD_HandleTildeModifiers(WCHAR **start, BOOL atExecute)
size = GetEnvironmentVariableW(env, NULL, 0);
if (size > 0) {
WCHAR *fullpath = heap_xalloc(size * sizeof(WCHAR));
WCHAR *fullpath = malloc(size * sizeof(WCHAR));
if (!fullpath || (GetEnvironmentVariableW(env, fullpath, size) == 0) ||
(SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0))
size = 0;
heap_free(fullpath);
free(fullpath);
}
if (!size) {

View File

@ -270,7 +270,7 @@ void WCMD_choice (const WCHAR * args) {
have_console = GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldmode);
errorlevel = 0;
my_command = heap_strdupW(WCMD_skip_leading_spaces((WCHAR*) args));
my_command = xstrdupW(WCMD_skip_leading_spaces((WCHAR*)args));
ptr = WCMD_skip_leading_spaces(my_command);
while (*ptr == '/') {
@ -283,7 +283,7 @@ void WCMD_choice (const WCHAR * args) {
if (!*ptr || iswspace(*ptr)) {
WINE_FIXME("bad parameter %s for /C\n", wine_dbgstr_w(ptr));
heap_free(my_command);
free(my_command);
return;
}
@ -320,7 +320,7 @@ void WCMD_choice (const WCHAR * args) {
if (!opt_default || (*ptr != ',')) {
WINE_FIXME("bad option %s for /T\n", opt_default ? wine_dbgstr_w(ptr) : "");
heap_free(my_command);
free(my_command);
return;
}
ptr++;
@ -339,7 +339,7 @@ void WCMD_choice (const WCHAR * args) {
default:
WINE_FIXME("bad parameter: %s\n", wine_dbgstr_w(ptr));
heap_free(my_command);
free(my_command);
return;
}
}
@ -386,7 +386,7 @@ void WCMD_choice (const WCHAR * args) {
answer[1] = 0; /* terminate single character string */
if (!WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), answer, 1, &count))
{
heap_free(my_command);
free(my_command);
errorlevel = 0;
return;
}
@ -403,7 +403,7 @@ void WCMD_choice (const WCHAR * args) {
errorlevel = (ptr - opt_c) + 1;
WINE_TRACE("answer: %ld\n", errorlevel);
heap_free(my_command);
free(my_command);
return;
}
else
@ -706,7 +706,7 @@ void WCMD_copy(WCHAR * args) {
}
/* We have found something to process - build a COPY_FILE block to store it */
thiscopy = heap_xalloc(sizeof(COPY_FILES));
thiscopy = xalloc(sizeof(COPY_FILES));
WINE_TRACE("Not a switch, but probably a filename/list %s\n", wine_dbgstr_w(thisparam));
thiscopy->concatenate = concatnextfilename;
@ -717,7 +717,7 @@ void WCMD_copy(WCHAR * args) {
leave space to append \* to the end) , then copy in character by character. Strip off
quotes if we find them. */
len = lstrlenW(thisparam) + (sizeof(WCHAR) * 5); /* 5 spare characters, null + \*.* */
thiscopy->name = heap_xalloc(len*sizeof(WCHAR));
thiscopy->name = xalloc(len * sizeof(WCHAR));
memset(thiscopy->name, 0x00, len);
pos1 = thisparam;
@ -796,7 +796,7 @@ void WCMD_copy(WCHAR * args) {
lstrcpyW(destname, L".");
lstrcatW(destname, L"\\");
destination = heap_xalloc(sizeof(COPY_FILES));
destination = xalloc(sizeof(COPY_FILES));
if (destination == NULL) goto exitreturn;
destination->concatenate = FALSE; /* Not used for destination */
destination->binarycopy = binarymode;
@ -856,8 +856,8 @@ void WCMD_copy(WCHAR * args) {
}
/* Save away the destination name*/
heap_free(destination->name);
destination->name = heap_strdupW(destname);
free(destination->name);
destination->name = xstrdupW(destname);
WINE_TRACE("Resolved destination is '%s' (calc later %d)\n",
wine_dbgstr_w(destname), appendfirstsource);
@ -984,8 +984,8 @@ void WCMD_copy(WCHAR * args) {
/* If we needed to save away the first filename, do it */
if (appendfirstsource && overwrite) {
heap_free(destination->name);
destination->name = heap_strdupW(outname);
free(destination->name);
destination->name = xstrdupW(outname);
WINE_TRACE("Final resolved destination name : '%s'\n", wine_dbgstr_w(outname));
appendfirstsource = FALSE;
destisdirectory = FALSE;
@ -1059,14 +1059,14 @@ exitreturn:
prevcopy = thiscopy;
/* Free up this block*/
thiscopy = thiscopy -> next;
heap_free(prevcopy->name);
heap_free(prevcopy);
free(prevcopy->name);
free(prevcopy);
}
/* Free up the destination memory */
if (destination) {
heap_free(destination->name);
heap_free(destination);
free(destination->name);
free(destination);
}
return;
@ -1371,12 +1371,12 @@ static BOOL WCMD_delete_one (const WCHAR *thisArg) {
WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(subParm));
/* Allocate memory, add to list */
nextDir = heap_xalloc(sizeof(DIRECTORY_STACK));
nextDir = xalloc(sizeof(DIRECTORY_STACK));
if (allDirs == NULL) allDirs = nextDir;
if (lastEntry != NULL) lastEntry->next = nextDir;
lastEntry = nextDir;
nextDir->next = NULL;
nextDir->dirName = heap_strdupW(subParm);
nextDir->dirName = xstrdupW(subParm);
}
} while (FindNextFileW(hff, &fd) != 0);
FindClose (hff);
@ -1388,8 +1388,8 @@ static BOOL WCMD_delete_one (const WCHAR *thisArg) {
tempDir = allDirs->next;
found |= WCMD_delete_one (allDirs->dirName);
heap_free(allDirs->dirName);
heap_free(allDirs);
free(allDirs->dirName);
free(allDirs);
allDirs = tempDir;
}
}
@ -1457,7 +1457,7 @@ static WCHAR *WCMD_strtrim(const WCHAR *s)
const WCHAR *start = s;
WCHAR* result;
result = heap_xalloc((len + 1) * sizeof(WCHAR));
result = xalloc((len + 1) * sizeof(WCHAR));
while (iswspace(*start)) start++;
if (*start) {
@ -1497,7 +1497,7 @@ void WCMD_echo (const WCHAR *args)
&& origcommand[0]!=';' && origcommand[0]!='/') {
if (echo_mode) WCMD_output(WCMD_LoadMessage(WCMD_ECHOPROMPT), L"ON");
else WCMD_output (WCMD_LoadMessage(WCMD_ECHOPROMPT), L"OFF");
heap_free(trimmed);
free(trimmed);
return;
}
@ -1509,7 +1509,7 @@ void WCMD_echo (const WCHAR *args)
WCMD_output_asis (args);
WCMD_output_asis(L"\r\n");
}
heap_free(trimmed);
free(trimmed);
}
/*****************************************************************************
@ -1533,9 +1533,9 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
/* Process the first command, if there is one */
if (executecmds && firstcmd && *firstcmd) {
WCHAR *command = heap_strdupW(firstcmd);
WCHAR *command = xstrdupW(firstcmd);
WCMD_execute (firstcmd, (*cmdList)->redirects, cmdList, FALSE);
heap_free(command);
free(command);
}
@ -1775,12 +1775,12 @@ static void WCMD_add_dirstowalk(DIRECTORY_STACK *dirsToWalk) {
debugstr_w(dirsToWalk->dirName), debugstr_w(fd.cFileName));
continue;
}
toWalk = heap_xalloc(sizeof(DIRECTORY_STACK));
toWalk = xalloc(sizeof(DIRECTORY_STACK));
WINE_TRACE("(%p->%p)\n", remainingDirs, remainingDirs->next);
toWalk->next = remainingDirs->next;
remainingDirs->next = toWalk;
remainingDirs = toWalk;
toWalk->dirName = heap_xalloc(sizeof(WCHAR) * (lstrlenW(dirsToWalk->dirName) + 2 + lstrlenW(fd.cFileName)));
toWalk->dirName = xalloc(sizeof(WCHAR) * (wcslen(dirsToWalk->dirName) + 2 + wcslen(fd.cFileName)));
lstrcpyW(toWalk->dirName, dirsToWalk->dirName);
lstrcatW(toWalk->dirName, L"\\");
lstrcatW(toWalk->dirName, fd.cFileName);
@ -2003,7 +2003,7 @@ static void WCMD_parse_line(CMD_LIST *cmdStart,
WINE_TRACE("Parsed token %d(%d) as parameter %s\n", nexttoken,
varidx + varoffset, wine_dbgstr_w(parm));
if (varidx >=0) {
if (parm) forloopcontext.variable[varidx + varoffset] = heap_strdupW(parm);
if (parm) forloopcontext.variable[varidx + varoffset] = xstrdupW(parm);
varoffset++;
if (((varidx%26)+varoffset) >= 26) break;
}
@ -2021,7 +2021,7 @@ static void WCMD_parse_line(CMD_LIST *cmdStart,
WCMD_parameter_with_delims(buffer, (nexttoken-1), &parm, FALSE, FALSE, forf_delims);
WINE_TRACE("Parsed allremaining tokens (%d) as parameter %s\n",
varidx + varoffset, wine_dbgstr_w(parm));
if (parm) forloopcontext.variable[varidx + varoffset] = heap_strdupW(parm);
if (parm) forloopcontext.variable[varidx + varoffset] = xstrdupW(parm);
}
/* Execute the body of the foor loop with these values */
@ -2038,7 +2038,7 @@ static void WCMD_parse_line(CMD_LIST *cmdStart,
for (i=varidx; i<MAX_FOR_VARIABLES; i++) {
if ((forloopcontext.variable[i] != oldcontext.variable[i]) &&
(forloopcontext.variable[i] != emptyW)) {
heap_free(forloopcontext.variable[i]);
free(forloopcontext.variable[i]);
}
}
}
@ -2103,7 +2103,7 @@ static FILE* WCMD_forf_getinput(BOOL usebackq, WCHAR *itemstr, BOOL iscmd) {
WINE_TRACE("Reading input to parse from '%s'\n", wine_dbgstr_w(itemstr));
ret = _wfopen(itemstr, L"rt,ccs=unicode");
}
heap_free(trimmed);
free(trimmed);
return ret;
}
@ -2209,9 +2209,9 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
/* Set up the list of directories to recurse if we are going to */
} else if (doRecurse) {
/* Allocate memory, add to list */
dirsToWalk = heap_xalloc(sizeof(DIRECTORY_STACK));
dirsToWalk = xalloc(sizeof(DIRECTORY_STACK));
dirsToWalk->next = NULL;
dirsToWalk->dirName = heap_strdupW(optionsRoot);
dirsToWalk->dirName = xstrdupW(optionsRoot);
WINE_TRACE("Starting with root directory %s\n", wine_dbgstr_w(dirsToWalk->dirName));
}
@ -2500,8 +2500,8 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
/* If we are walking directories, move on to any which remain */
if (dirsToWalk != NULL) {
DIRECTORY_STACK *nextDir = dirsToWalk->next;
heap_free(dirsToWalk->dirName);
heap_free(dirsToWalk);
free(dirsToWalk->dirName);
free(dirsToWalk);
dirsToWalk = nextDir;
if (dirsToWalk) WINE_TRACE("Moving to next directory to iterate: %s\n",
wine_dbgstr_w(dirsToWalk->dirName));
@ -3666,7 +3666,7 @@ static int WCMD_getprecedence(const WCHAR in)
* stack
*/
static void WCMD_pushnumber(WCHAR *var, int num, VARSTACK **varstack) {
VARSTACK *thisstack = heap_xalloc(sizeof(VARSTACK));
VARSTACK *thisstack = xalloc(sizeof(VARSTACK));
thisstack->isnum = (var == NULL);
if (var) {
thisstack->variable = var;
@ -3716,9 +3716,9 @@ static int WCMD_popnumber(VARSTACK **varstack) {
if (varstack) {
thisvar = *varstack;
result = WCMD_peeknumber(varstack);
if (!thisvar->isnum) heap_free(thisvar->variable);
if (!thisvar->isnum) free(thisvar->variable);
*varstack = thisvar->next;
heap_free(thisvar);
free(thisvar);
}
WINE_TRACE("Popped number %d\n", result);
return result;
@ -3729,7 +3729,7 @@ static int WCMD_popnumber(VARSTACK **varstack) {
* Push an operator onto the supplied stack
*/
static void WCMD_pushoperator(WCHAR op, int precedence, OPSTACK **opstack) {
OPSTACK *thisstack = heap_xalloc(sizeof(OPSTACK));
OPSTACK *thisstack = xalloc(sizeof(OPSTACK));
thisstack->precedence = precedence;
thisstack->op = op;
thisstack->next = *opstack;
@ -3750,7 +3750,7 @@ static WCHAR WCMD_popoperator(OPSTACK **opstack) {
thisop = *opstack;
result = thisop->op;
*opstack = thisop->next;
heap_free(thisop);
free(thisop);
}
WINE_TRACE("Popped operator %c\n", result);
return result;
@ -3954,7 +3954,7 @@ static int WCMD_handleExpression(WCHAR **expr, int *ret, int depth)
/* For a variable - just push it onto the stack */
parm = WCMD_parameter_with_delims(pos, 0, &parmstart, FALSE, FALSE, mathDelims);
dupparm = heap_strdupW(parm);
dupparm = xstrdupW(parm);
WCMD_pushnumber(dupparm, 0, &varstackhead);
pos = parmstart + lstrlenW(dupparm);
}
@ -4064,7 +4064,7 @@ static int WCMD_handleExpression(WCHAR **expr, int *ret, int depth)
}
prevresult = WCMD_popnumber(&varstackhead);
WINE_TRACE("Expression resolved to %d\n", prevresult);
heap_free(varstackhead);
free(varstackhead);
varstackhead = NULL;
pos++;
break;
@ -4194,7 +4194,7 @@ void WCMD_setshow_env (WCHAR *s) {
WCHAR *src,*dst;
/* Remove all quotes before doing any calculations */
thisexpr = heap_xalloc((lstrlenW(s+2)+1) * sizeof(WCHAR));
thisexpr = xalloc((wcslen(s + 2) + 1) * sizeof(WCHAR));
src = s+2;
dst = thisexpr;
while (*src) {
@ -4206,7 +4206,7 @@ void WCMD_setshow_env (WCHAR *s) {
/* Now calculate the results of the expression */
src = thisexpr;
rc = WCMD_handleExpression(&src, &result, 0);
heap_free(thisexpr);
free(thisexpr);
/* If parsing failed, issue the error message */
if (rc > 0) {
@ -4385,7 +4385,7 @@ void WCMD_start(WCHAR *args)
GetSystemDirectoryW( file, MAX_PATH );
lstrcatW(file, L"\\start.exe");
cmdline = heap_xalloc( (lstrlenW(file) + lstrlenW(args) + 8) * sizeof(WCHAR) );
cmdline = xalloc( (wcslen(file) + wcslen(args) + 8) * sizeof(WCHAR) );
lstrcpyW( cmdline, file );
lstrcatW(cmdline, L" ");
cmdline_params = cmdline + lstrlenW(cmdline);
@ -4488,7 +4488,7 @@ void WCMD_start(WCHAR *args)
WCMD_print_error ();
errorlevel = 9009;
}
heap_free(cmdline);
free(cmdline);
}
/****************************************************************************

View File

@ -182,18 +182,18 @@ static void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen) {
ULONG domainLen = MAXSTRING;
SID_NAME_USE nameuse;
secBuffer = heap_xalloc(sizeNeeded * sizeof(BYTE));
secBuffer = xalloc(sizeNeeded * sizeof(BYTE));
/* Get the owners security descriptor */
if(!GetFileSecurityW(filename, OWNER_SECURITY_INFORMATION, secBuffer,
sizeNeeded, &sizeNeeded)) {
heap_free(secBuffer);
free(secBuffer);
return;
}
/* Get the SID from the SD */
if(!GetSecurityDescriptorOwner(secBuffer, &pSID, &defaulted)) {
heap_free(secBuffer);
free(secBuffer);
return;
}
@ -201,7 +201,7 @@ static void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen) {
if (LookupAccountSidW(NULL, pSID, name, &nameLen, domain, &domainLen, &nameuse)) {
swprintf(owner, ownerlen, L"%s%c%s", domain, '\\', name);
}
heap_free(secBuffer);
free(secBuffer);
}
return;
}
@ -242,7 +242,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
same directory. Note issuing a directory header with no contents
mirrors what windows does */
parms = inputparms;
fd = heap_xalloc(sizeof(WIN32_FIND_DATAW));
fd = xalloc(sizeof(WIN32_FIND_DATAW));
while (parms && lstrcmpW(inputparms->dirName, parms->dirName) == 0) {
concurrentDirs++;
@ -267,7 +267,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
if (tmpLen > widest) widest = tmpLen;
}
fd = HeapReAlloc(GetProcessHeap(),0,fd,(entry_count+1)*sizeof(WIN32_FIND_DATAW));
fd = realloc(fd, (entry_count + 1) * sizeof(WIN32_FIND_DATAW));
if (fd == NULL) {
FindClose (hff);
WINE_ERR("Out of memory\n");
@ -431,7 +431,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
}
}
}
heap_free(fd);
free(fd);
/* When recursing, look in all subdirectories for matches */
if (recurse) {
@ -466,13 +466,13 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(string));
/* Allocate memory, add to list */
thisDir = heap_xalloc(sizeof(DIRECTORY_STACK));
thisDir = xalloc(sizeof(DIRECTORY_STACK));
if (dirStack == NULL) dirStack = thisDir;
if (lastEntry != NULL) lastEntry->next = thisDir;
lastEntry = thisDir;
thisDir->next = NULL;
thisDir->dirName = heap_strdupW(string);
thisDir->fileName = heap_strdupW(parms->fileName);
thisDir->dirName = xstrdupW(string);
thisDir->fileName = xstrdupW(parms->fileName);
parms = parms->next;
}
}
@ -484,9 +484,9 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
dirStack = WCMD_list_directory (thisDir, 1);
while (thisDir != dirStack) {
DIRECTORY_STACK *tempDir = thisDir->next;
heap_free(thisDir->dirName);
heap_free(thisDir->fileName);
heap_free(thisDir);
free(thisDir->dirName);
free(thisDir->fileName);
free(thisDir);
thisDir = tempDir;
}
}
@ -786,7 +786,7 @@ void WCMD_directory (WCHAR *args)
}
WINE_TRACE("Using path '%s'\n", wine_dbgstr_w(path));
thisEntry = heap_xalloc(sizeof(DIRECTORY_STACK));
thisEntry = xalloc(sizeof(DIRECTORY_STACK));
if (fullParms == NULL) fullParms = thisEntry;
if (prevEntry != NULL) prevEntry->next = thisEntry;
prevEntry = thisEntry;
@ -798,11 +798,11 @@ void WCMD_directory (WCHAR *args)
wine_dbgstr_w(drive), wine_dbgstr_w(dir),
wine_dbgstr_w(fname), wine_dbgstr_w(ext));
thisEntry->dirName = heap_xalloc(sizeof(WCHAR) * (lstrlenW(drive)+lstrlenW(dir)+1));
thisEntry->dirName = xalloc(sizeof(WCHAR) * (wcslen(drive) + wcslen(dir) + 1));
lstrcpyW(thisEntry->dirName, drive);
lstrcatW(thisEntry->dirName, dir);
thisEntry->fileName = heap_xalloc(sizeof(WCHAR) * (lstrlenW(fname)+lstrlenW(ext)+1));
thisEntry->fileName = xalloc(sizeof(WCHAR) * (wcslen(fname) + wcslen(ext) + 1));
lstrcpyW(thisEntry->fileName, fname);
lstrcatW(thisEntry->fileName, ext);
@ -812,10 +812,10 @@ void WCMD_directory (WCHAR *args)
/* If just 'dir' entered, a '*' parameter is assumed */
if (fullParms == NULL) {
WINE_TRACE("Inserting default '*'\n");
fullParms = heap_xalloc(sizeof(DIRECTORY_STACK));
fullParms = xalloc(sizeof(DIRECTORY_STACK));
fullParms->next = NULL;
fullParms->dirName = heap_strdupW(cwd);
fullParms->fileName = heap_strdupW(L"*");
fullParms->dirName = xstrdupW(cwd);
fullParms->fileName = xstrdupW(L"*");
}
lastDrive = '?';
@ -872,8 +872,8 @@ exit:
while (fullParms != NULL) {
prevEntry = fullParms;
fullParms = prevEntry->next;
heap_free(prevEntry->dirName);
heap_free(prevEntry->fileName);
heap_free(prevEntry);
free(prevEntry->dirName);
free(prevEntry->fileName);
free(prevEntry);
}
}

View File

@ -30,7 +30,6 @@
#include <stdio.h>
#include <ctype.h>
#include <wchar.h>
#include <wine/heap.h>
/* msdn specified max for Win XP */
#define MAXSTRING 8192
@ -125,9 +124,9 @@ void WCMD_free_commands(CMD_LIST *cmds);
void WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects,
CMD_LIST **cmdList, BOOL retrycall);
void *heap_xalloc(size_t);
void *xalloc(size_t) __WINE_ALLOC_SIZE(1) __WINE_DEALLOC(free) __WINE_MALLOC;
static inline WCHAR *heap_strdupW(const WCHAR *str)
static inline WCHAR *xstrdupW(const WCHAR *str)
{
WCHAR *ret = NULL;
@ -135,7 +134,7 @@ static inline WCHAR *heap_strdupW(const WCHAR *str)
size_t size;
size = (lstrlenW(str)+1)*sizeof(WCHAR);
ret = heap_xalloc(size);
ret = xalloc(size);
memcpy(ret, str, size);
}

View File

@ -67,7 +67,7 @@ static char *get_file_buffer(void)
{
static char *output_bufA = NULL;
if (!output_bufA)
output_bufA = heap_xalloc(MAX_WRITECONSOLE_SIZE);
output_bufA = xalloc(MAX_WRITECONSOLE_SIZE);
return output_bufA;
}
@ -423,11 +423,11 @@ static void WCMD_show_prompt (BOOL newLine) {
WCMD_output_asis (out_string);
}
void *heap_xalloc(size_t size)
void *xalloc(size_t size)
{
void *ret;
ret = heap_alloc(size);
ret = malloc(size);
if(!ret) {
ERR("Out of memory\n");
ExitProcess(1);
@ -732,16 +732,16 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start, WCHAR startchar)
WCHAR *searchFor;
if (equalspos == NULL) return start+1;
s = heap_strdupW(endOfVar + 1);
s = xstrdupW(endOfVar + 1);
/* Null terminate both strings */
thisVar[lstrlenW(thisVar)-1] = 0x00;
*equalspos = 0x00;
/* Since we need to be case insensitive, copy the 2 buffers */
searchIn = heap_strdupW(thisVarContents);
searchIn = xstrdupW(thisVarContents);
CharUpperBuffW(searchIn, lstrlenW(thisVarContents));
searchFor = heap_strdupW(colonpos+1);
searchFor = xstrdupW(colonpos + 1);
CharUpperBuffW(searchFor, lstrlenW(colonpos+1));
/* Handle wildcard case */
@ -779,9 +779,9 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start, WCHAR startchar)
thisVarContents + (lastFound-searchIn));
lstrcatW(outputposn, s);
}
heap_free(s);
heap_free(searchIn);
heap_free(searchFor);
free(s);
free(searchIn);
free(searchFor);
}
return start;
}
@ -971,7 +971,7 @@ static void init_msvcrt_io_block(STARTUPINFOW* st)
* its new input & output handles)
*/
sz = max(sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * 3, st_p.cbReserved2);
ptr = heap_xalloc(sz);
ptr = xalloc(sz);
flags = (char*)(ptr + sizeof(unsigned));
handles = (HANDLE*)(flags + num * sizeof(char));
@ -1221,7 +1221,7 @@ void WCMD_run_program (WCHAR *command, BOOL called)
Note: Launching internal wine processes cannot specify a full path to exe */
status = CreateProcessW(thisDir,
command, NULL, NULL, TRUE, 0, NULL, NULL, &st, &pe);
heap_free(st.lpReserved2);
free(st.lpReserved2);
if ((opt_c || opt_k) && !opt_s && !status
&& GetLastError()==ERROR_FILE_NOT_FOUND && command[0]=='\"') {
/* strip first and last quote WCHARacters and try again */
@ -1301,12 +1301,12 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
wine_dbgstr_w(command), cmdList);
/* Move copy of the command onto the heap so it can be expanded */
new_cmd = heap_xalloc(MAXSTRING * sizeof(WCHAR));
new_cmd = xalloc(MAXSTRING * sizeof(WCHAR));
lstrcpyW(new_cmd, command);
cmd = new_cmd;
/* Move copy of the redirects onto the heap so it can be expanded */
new_redir = heap_xalloc(MAXSTRING * sizeof(WCHAR));
new_redir = xalloc(MAXSTRING * sizeof(WCHAR));
redir = new_redir;
/* Strip leading whitespaces, and a '@' if supplied */
@ -1389,8 +1389,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
WINE_TRACE("Got directory %s as %s\n", wine_dbgstr_w(envvar), wine_dbgstr_w(cmd));
status = SetCurrentDirectoryW(cmd);
if (!status) WCMD_print_error ();
heap_free(cmd );
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
@ -1412,8 +1412,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
SetStdHandle (STD_INPUT_HANDLE, h);
@ -1427,8 +1427,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
&sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
SetStdHandle (STD_INPUT_HANDLE, h);
@ -1472,8 +1472,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
&sa, creationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error ();
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
return;
}
if (SetFilePointer (h, 0, NULL, FILE_END) ==
@ -1643,8 +1643,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
WCMD_run_program (whichcmd, FALSE);
echo_mode = prev_echo_mode;
}
heap_free(cmd);
heap_free(new_redir);
free(cmd);
free(new_redir);
/* Restore old handles */
for (i=0; i<3; i++) {
@ -1705,16 +1705,16 @@ static void WCMD_addCommand(WCHAR *command, int *commandLen,
CMD_LIST *thisEntry = NULL;
/* Allocate storage for command */
thisEntry = heap_xalloc(sizeof(CMD_LIST));
thisEntry = xalloc(sizeof(CMD_LIST));
/* Copy in the command */
if (command) {
thisEntry->command = heap_xalloc((*commandLen+1) * sizeof(WCHAR));
thisEntry->command = xalloc((*commandLen + 1) * sizeof(WCHAR));
memcpy(thisEntry->command, command, *commandLen * sizeof(WCHAR));
thisEntry->command[*commandLen] = 0x00;
/* Copy in the redirects */
thisEntry->redirects = heap_xalloc((*redirLen+1) * sizeof(WCHAR));
thisEntry->redirects = xalloc((*redirLen + 1) * sizeof(WCHAR));
memcpy(thisEntry->redirects, redirs, *redirLen * sizeof(WCHAR));
thisEntry->redirects[*redirLen] = 0x00;
thisEntry->pipeFile[0] = 0x00;
@ -1845,7 +1845,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
/* Allocate working space for a command read from keyboard, file etc */
if (!extraSpace)
extraSpace = heap_xalloc((MAXSTRING+1) * sizeof(WCHAR));
extraSpace = xalloc((MAXSTRING + 1) * sizeof(WCHAR));
if (!extraSpace)
{
WINE_ERR("Could not allocate memory for extraSpace\n");
@ -2399,9 +2399,9 @@ void WCMD_free_commands(CMD_LIST *cmds) {
while (cmds) {
CMD_LIST *thisCmd = cmds;
cmds = cmds->nextcommand;
heap_free(thisCmd->command);
heap_free(thisCmd->redirects);
heap_free(thisCmd);
free(thisCmd->command);
free(thisCmd->redirects);
free(thisCmd);
}
}
@ -2516,7 +2516,7 @@ int __cdecl wmain (int argc, WCHAR *argvW[])
WCHAR *q1 = NULL,*q2 = NULL,*p;
/* Take a copy */
cmd = heap_strdupW(arg);
cmd = xstrdupW(arg);
/* opt_s left unflagged if the command starts with and contains exactly
* one quoted string (exactly two quote characters). The quoted string
@ -2674,7 +2674,7 @@ int __cdecl wmain (int argc, WCHAR *argvW[])
WCMD_free_commands(toExecute);
toExecute = NULL;
heap_free(cmd);
free(cmd);
return errorlevel;
}
@ -2754,7 +2754,7 @@ int __cdecl wmain (int argc, WCHAR *argvW[])
WCMD_process_commands(toExecute, FALSE, FALSE);
WCMD_free_commands(toExecute);
toExecute = NULL;
heap_free(cmd);
free(cmd);
}
/*